description
stringlengths
171
4k
code
stringlengths
94
3.98k
normalized_code
stringlengths
57
4.99k
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
from sys import stdin mod = 1000 * 1000 * 1000 + 7 for i in range(int(stdin.readline())): l, r = map(int, stdin.readline().split()) act = 0 req = 0 ans = 0 for i in range(60): val = min(r - l + 1, req - act + 1) val %= mod if l & 1 << i: ans += val * ((1 << i) % mod) % mod ans %= mod act += 1 << i req += 1 << i print(ans)
ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER NUMBER 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 NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP NUMBER VAR VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
t = int(input()) while t: t -= 1 l, r = map(int, input().split()) ans = 0 for i in range(60): if l >> i & 1 ^ 1: continue l2 = min((l >> i) + 1 << i, r + 1) ans += (l2 - l) * (1 << i) % (10**9 + 7) ans %= 10**9 + 7 print(ans % (10**9 + 7))
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 NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
def rand(l, r): mod = 10**9 + 7 binary = bin(l)[2:] a, b, res = 1, 0, 0 for i in range(len(binary) - 1, -1, -1): if binary[i] == "1": res += a * min(a - b, r - l + 1) res %= mod b += a a *= 2 return res for _ in range(int(input())): a, b = map(int, input().split()) print(rand(a, b))
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
t = int(input()) mod = 10**9 + 7 for _ in range(t): l, r = map(int, input().split()) if l == r: print(l % mod) continue a = bin(l)[2:] b = bin(r)[2:] a = "0" * (len(b) - len(a)) + a ind = 0 while a[ind] == b[ind]: ind += 1 ans = 0 cnt = 0 flag = 0 for i in range(len(a) - 1, -1, -1): if flag == 1: break if a[i] == "0": cnt += 1 if i == ind: flag = 1 continue if i == len(a) - 1: ans += 1 else: ans += 2**cnt * (2**cnt - 1 - int(a[i + 1 :], 2) + 1) if i == ind: break cnt += 1 for i in range(ind - 1, -1, -1): if a[i] == "0": cnt += 1 continue if i == len(a) - 1: ans += 1 else: ans += 2**cnt * (int(b[i + 1 :], 2) - int(a[i + 1 :], 2) + 1) cnt += 1 print(ans % mod)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF VAR VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
from sys import stdin def solve(): for _ in range(int(stdin.readline())): l, r = map(int, stdin.readline().split()) a = bin(l)[2:] n = len(a) ci, k, res = 0, 0, 0 for i in range(n): if a[n - 1 - i] == "1": k = l + (2**i - (2**i - 1 & l)) ci = min(k - l, r - l + 1) res += ci * 2**i print(res % 1000000007) solve()
FUNC_DEF 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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
MVAL = 1000000007 def rangeand(low, hi): ra = 0 p2 = 1 lmd = 0 ldv = low hdv = hi while p2 <= low: thisbit = low & p2 p2 *= 2 ldv //= 2 hdv //= 2 if ldv == hdv: ra += (hi + 1 - low) * (low - lmd) % MVAL break elif thisbit > 0: lmd += thisbit ra += (p2 - lmd) * thisbit % MVAL return ra % MVAL t = int(input()) for ti in range(t): l, r = list(map(int, input().split())) print(rangeand(l, r))
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR RETURN BIN_OP VAR VAR 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
T = int(input()) for _ in range(T): a, b = map(int, input().split()) a1 = a b1 = b p = a ans = 0 x = 1 y = a - 1 z = a while a > 0: r = a % 2 if r == 1: z = p + x - 1 if z <= b: ans = ans + p * (z - y) else: ans += p * (b - y) break y = z p = p - x a = a // 2 x = x * 2 ans = ans % 1000000007 print(ans % 1000000007)
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 VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
You are given positive integers $L$ and $R$. You have to find the sum S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,, where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing one integer — the sum $S$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 10^5$ - $1 \le L \le R \le 10^{18}$ -----Example Input----- 2 1 4 4 10 -----Example Output----- 1 16 -----Explanation----- Example case 1: The sum is 1 + 1 AND 2 + 1 AND 2 AND 3 + 1 AND 2 AND 3 AND 4 = 1 + 0 + 0 + 0 = 1. Example case 2: The sum is 4 + 4 AND 5 + 4 AND 5 AND 6 + 4 AND 5 AND 6 AND 7 + … + 4 AND 5 AND … AND 10 = 4 + 4 + … + 0 = 16.
mod = 10**9 + 7 for _ in range(int(input())): l, r = map(int, input().split()) z = 2 while z <= l: z *= 2 if r > z: r = z - 1 z = z // 2 ans = l lb = bin(l).replace("0b", "") for i in lb: if i != "0": h = l % z h = z - h - 1 if h >= r - l: g = r % z g = z - g - 1 if g < h: h = h - g ans += h * z z = z // 2 print(ans % mod)
ASSIGN VAR BIN_OP BIN_OP NUMBER 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 NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING FOR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) a, b = 1023, 0 for _ in range(n): c, d = input().split() d = int(d) if c == "|": a, b = a | d, b | d elif c == "&": a, b = a & d, b & d elif c == "^": a, b = a ^ d, b ^ d print("2\n| {}\n^ {}".format(a ^ b ^ 1023, a ^ 1023))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
import sys input = sys.stdin.readline n = int(input()) start1 = 0 start2 = 1023 for _ in range(n): a, b = map(str, input().split()) b = int(b) if a == "|": start1 = b | start1 start2 = b | start2 elif a == "^": start1 = b ^ start1 start2 = b ^ start2 else: start1 = b & start1 start2 = b & start2 ans = [] ands = 1023 xors = 0 ors = 0 for i in range(10): k = 1 << i if start1 & k and start2 & k: ors += k elif start1 & k and not start2 & k: xors += k elif not start1 & k and not start2 & k: ands -= k print(3) print("&", ands) print("^", xors) print("|", ors)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) m = 2**10 - 1 a = 0 b = m for _ in range(n): op, l = input().split() v = int(l) if op == "|": a |= v b |= v elif op == "&": a &= v b &= v else: a ^= v b ^= v print(3) print("&", a | b) print("|", a & b) print("^", a & (b ^ m))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR BIN_OP VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import stdin, stdout def input(): return stdin.readline().strip() def run_program(n, program): for op, a in program: assert op in "&|^" if op == "&": n = n & a if op == "|": n = n | a if op == "^": n = n ^ a return n N = int(input()) q = 1023 r = 0 original_program = [] for _ in range(N): op, s = input().split(" ") s = int(s) original_program += [(op, s)] if op == "&": q = q & s r = r & s elif op == "^": r = r ^ s elif op == "|": q, r = q ^ q & s, r ^ s ^ r & s else: assert False final_program = [("&", q), ("^", r)] print(2) print(f"& {q}") print(f"^ {r}")
FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR VAR VAR VAR STRING IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR LIST VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR LIST STRING VAR STRING VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
import sys n = int(sys.stdin.readline()) zero_result = 0 ones_result = 1023 while n > 0: [op, val] = sys.stdin.readline().split(" ") val = int(val) n -= 1 if op == "&": zero_result = zero_result & val ones_result = ones_result & val elif op == "|": zero_result = zero_result | val ones_result = ones_result | val elif op == "^": zero_result = zero_result ^ val ones_result = ones_result ^ val else: pass and_bin = [(1) for i in range(10)] or_bin = [(0) for i in range(10)] xor_bin = [(0) for i in range(10)] for i in range(10): j = 9 - i zero_digit = zero_result >> j ones_digit = ones_result >> j zero_result = zero_result - zero_digit * 2**j ones_result = ones_result - ones_digit * 2**j if zero_digit == 0 and ones_digit == 0: and_bin[j] = 0 elif zero_digit == 1 and ones_digit == 0: xor_bin[j] = 1 elif zero_digit == 1 and ones_digit == 1: or_bin[j] = 1 and_int = 0 xor_int = 0 or_int = 0 for i in range(10): and_int += and_bin[i] * 2**i or_int += or_bin[i] * 2**i xor_int += xor_bin[i] * 2**i print(3) print("&", and_int) print("|", or_int) print("^", xor_int)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN LIST VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import stdin data = stdin.readlines() remain = -10 invert = -20 m = [remain] * 10 for i, st in enumerate(data): if i == 0: continue op, x = st.strip().split() x = int(x) for j in range(10): bit = x % 2 if op == "&" and bit == 0: m[j] = 0 elif op == "|" and bit == 1: m[j] = 1 elif op == "^" and bit == 1: if m[j] == 0: m[j] = 1 elif m[j] == 1: m[j] = 0 elif m[j] == remain: m[j] = invert elif m[j] == invert: m[j] = remain x = x // 2 print(3) and_const = 0 for i, v in enumerate(m): if v != 0: and_const += 2**i or_const = 0 for i, v in enumerate(m): if v == 1: or_const += 2**i xor_const = 0 for i, v in enumerate(m): if v == invert: xor_const += 2**i print("&", and_const) print("|", or_const) print("^", xor_const)
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) zero = 0 ones = 1023 for _ in range(n): op, num = input().split() num = int(num) if op == "&": zero &= num ones &= num elif op == "|": zero |= num ones |= num else: zero ^= num ones ^= num and_bits = 0 or_bits = 0 xor_bits = 0 for i in range(10): z = zero >> i & 1 o = ones >> i & 1 if z == 0 and o == 0: and_bits |= 0 << i or_bits |= 0 << i xor_bits |= 0 << i elif z == 0 and o == 1: and_bits |= 1 << i or_bits |= 0 << i xor_bits |= 0 << i elif z == 1 and o == 0: and_bits |= 1 << i or_bits |= 0 << i xor_bits |= 1 << i else: and_bits |= 1 << i or_bits |= 1 << i xor_bits |= 0 << i print(3) print("& {}".format(and_bits)) print("| {}".format(or_bits)) print("^ {}".format(xor_bits))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import stdin, stdout n = int(stdin.readline()) a = list() y = 0 for i in range(n): oper, x = stdin.readline().split() x = int(x) a.append((oper, x)) if oper == "&": y &= x elif oper == "|": y |= x elif oper == "^": y ^= x AND = (1 << 10) - 1 OR = 0 XOR = 0 for k in range(10): cur = 1 << k for comm in a: oper, x = comm if oper == "&": cur &= x elif oper == "|": cur |= x elif oper == "^": cur ^= x res0 = y & 1 << k res1 = cur & 1 << k if not res0 and not res1: AND ^= 1 << k elif not res0 and res1: pass elif res0 and not res1: XOR ^= 1 << k else: OR ^= 1 << k print(3) print("& ", AND) print("| ", OR) print("^ ", XOR)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
def execute(prg, n): for op, x in prg: if op == "|": n |= x elif op == "&": n &= x elif op == "^": n ^= x return n n = int(input()) prg = [] for i in range(n): op, x = map(str, input().split()) x = int(x) prg.append((op, x)) zeroes = execute(prg, 0) ones = execute(prg, 1023) orx, andx, xorx = 0, 0, 0 for i in range(10): bit = 1 << i if zeroes & bit == 0 and ones & bit == 0: pass elif zeroes & bit == 0 and ones & bit != 0: andx |= bit elif zeroes & bit != 0 and ones & bit == 0: xorx |= bit andx |= bit elif zeroes & bit != 0 and ones & bit != 0: orx |= bit andx |= bit print(3) print("|", orx) print("&", andx) print("^", xorx)
FUNC_DEF FOR VAR VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
z = 0 o = 1023 n = int(input()) for i in range(n): a, b = input().split() b = int(b) if a == "&": z = z & b o = o & b if a == "^": z = z ^ b o = o ^ b if a == "|": z = z | b o = o | b z = "{:010b}".format(z) o = "{:010b}".format(o) an = 0 r = 0 xo = 0 pw = 512 for i in range(10): an += pw if o[i] == "0" and z[i] == "0": an -= pw if o[i] == "1" and z[i] == "1": r += pw if o[i] == "0" and z[i] == "1": xo += pw pw //= 2 print(3) print("&", an) print("|", r) print("^", xo)
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR IF VAR VAR STRING VAR VAR STRING VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import stdin n = int(input()) s = [] c = 0 c1 = 1023 for i in range(n): st, num = map(str, stdin.readline().split()) num = int(num) if st == "&": c &= num c1 &= num elif st == "|": c |= num c1 |= num else: c ^= num c1 ^= num xornum = ~c1 ornum = ~(c ^ c1) xornum &= 1023 ornum &= 1023 print(2) print("|", ornum) print("^", xornum)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
q = int(input()) def calc(f): ret1 = 0 ret2 = 1023 for op in f: if op[0] == "&": ret1 &= op[1] ret2 &= op[1] elif op[0] == "|": ret1 |= op[1] ret2 |= op[1] elif op[0] == "^": ret1 ^= op[1] ret2 ^= op[1] return ret1, ret2 f = list() for i in range(q): oper, n = input().split() n = int(n) f.append((oper, n)) op0, op1 = calc(f) op0 = ("0000000000" + bin(op0)[2:])[-10:][::-1] op1 = ("0000000000" + bin(op1)[2:])[-10:][::-1] o = 0 x = 0 for i in range(10): if op0[i] == "1" and op1[i] == "1": o += 2**i elif op0[i] == "1" and op1[i] == "0": x += 2**i elif op0[i] == "0" and op1[i] == "0": o += 2**i x += 2**i print(2) print("| " + str(o)) print("^ " + str(x))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER STRING VAR VAR NUMBER VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR BIN_OP NUMBER VAR IF VAR VAR STRING VAR VAR STRING VAR BIN_OP NUMBER VAR IF VAR VAR STRING VAR VAR STRING VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
def fun(n1, o, n2): if o == "|": return n1 | n2 elif o == "&": return n1 & n2 else: return n1 ^ n2 def fun2(n): l = [(0) for i in range(10)] for i in range(9, -1, -1): if 1 << i <= n: l[i] = 1 n -= 1 << i return l n = int(input()) a = 0 b = 1023 for i in range(n): o, n2 = input().split() n2 = int(n2) a = fun(a, o, n2) b = fun(b, o, n2) l1 = fun2(a) l2 = fun2(b) a = 0 b = 0 for i in range(10): if l1[i] == 1 and l2[i] == 1: a += 1 << i elif l1[i] == 0 and l2[i] == 0: a += 1 << i b += 1 << i elif l1[i] == 1 and l2[i] == 0: b += 1 << i print(2) print("|", a) print("^", b)
FUNC_DEF IF VAR STRING RETURN BIN_OP VAR VAR IF VAR STRING RETURN BIN_OP VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
def simu(P, i): for c, x in P: if c == "&": i &= x elif c == "|": i |= x else: i ^= x return i def simpl(P): out0, out1 = simu(P, 0), simu(P, 1023) A, O, X = 1023, 0, 0 for i in range(10): B01 = out0 >> i & 1, out1 >> i & 1 if B01 == (0, 0): A ^= 1 << i elif B01 == (1, 0): X |= 1 << i elif B01 == (1, 1): O |= 1 << i return A, O, X def main(): n = int(input()) P = [] for _ in range(n): c, x = input().split() P.append((c, int(x))) A, O, X = simpl(P) print(3) print("&", A) print("|", O) print("^", X) main()
FUNC_DEF FOR VAR VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR RETURN VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
def solve(): n = int(input()) a = 0 b = 1023 for i in range(n): op, k = input().split() k = int(k) if op == "|": a |= k b |= k if op == "^": a ^= k b ^= k if op == "&": a &= k b &= k p = 1 print(3) aa = a bb = b ans = 0 for i in range(10): if aa % 2 == 1 and bb % 2 == 0: ans += p p *= 2 aa //= 2 bb //= 2 print("^", ans) p = 1 ans = 1023 aa = a bb = b for i in range(10): if aa % 2 == 0 and bb % 2 == 0: ans -= p p *= 2 aa //= 2 bb //= 2 print("&", ans) p = 1 ans = 0 aa = a bb = b for i in range(10): if aa % 2 == 1 and bb % 2 == 1: ans += p p *= 2 aa //= 2 bb //= 2 print("|", ans) return def main(): t = 1 for _ in range(t): solve() main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING VAR RETURN FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
import sys n = int(sys.stdin.readline()) zero_model, one_model = 0, (1 << 10) - 1 commands = [] for i in range(n): c, k = sys.stdin.readline()[:-1].split() k = int(k) commands.append((c, k)) def process(n, commands): for comm in commands: c, k = comm if c == "|": n |= k elif c == "^": n ^= k elif c == "&": n &= k return n zero_model = process(0, commands) one_model = process((1 << 10) - 1, commands) set_zero = (1 << 10) - 1 flip = 0 set_one = 0 for i in range(10): bz = zero_model & 1 << i bo = one_model & 1 << i if bz >= 1 and bo == 0: flip |= 1 << i elif bz >= 1 and bo >= 1: set_one |= 1 << i elif bz == 0 and bo == 0: set_zero &= ~(1 << i) ans = [("&", set_zero), ("^", flip), ("|", set_one)] print(len(ans)) for comm in ans: print(*comm)
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR FUNC_DEF FOR VAR VAR ASSIGN VAR VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR IF VAR STRING VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR LIST STRING VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import stdin BITCOUNT = 10 xONES = (1 << 10) - 1 xZEROS = 0 n = int(stdin.readline()) for i in range(n): op, num = stdin.readline().split() num = int(num) if op == "&": xONES &= num xZEROS &= num elif op == "|": xONES |= num xZEROS |= num else: xONES ^= num xZEROS ^= num andmask = 0 xormask = 0 mask = 1 for i in range(BITCOUNT): ONESbit = xONES >> i & 1 ZEROSbit = xZEROS >> i & 1 if ONESbit == 1 and ZEROSbit == 0: andmask += mask elif ONESbit == 0 and ZEROSbit == 1: andmask += mask xormask += mask elif ONESbit == 1 and ZEROSbit == 1: xormask += mask mask *= 2 print(2) print("& {}".format(andmask)) print("^ {}".format(xormask))
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) mask_ans1 = 1023 mask_ans2 = 0 for i in range(n): com, x = input().split() x = int(x) if com == "&": mask_ans1 &= x mask_ans2 &= x elif com == "|": mask_ans1 |= x mask_ans2 |= x elif com == "^": mask_ans1 ^= x mask_ans2 ^= x ans11 = 1023 & ~mask_ans2 ans12 = mask_ans1 ans13 = 1023 & (1023 ^ mask_ans1) ans1 = 1023 ^ 1023 & ~mask_ans1 & ans11 ans2 = mask_ans2 & ans12 ans3 = 1023 & (mask_ans2 ^ 0) & ans13 lst = [] cnt = 3 if ans1 == 1023: cnt -= 1 if ans2 == 0: cnt -= 1 if ans3 == 0: cnt -= 1 print(cnt) if ans1 != 1023: print("&", ans1) if ans2 != 0: print("|", ans2) if ans3 != 0: print("^", ans3)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import stdin, stdout class Solve: def __init__(self): R = stdin.readline W = stdout.write n = int(input()) z, o = 0, 1023 for i in range(n): op, x = R().split() x = int(x) if op == "|": z |= x o |= x elif op == "&": z &= x o &= x elif op == "^": z ^= x o ^= x ans = {"^": 0, "|": 0, "&": 1023} for b in range(10): bit = 1 << b bitz = z & bit bito = o & bit if bool(bitz) and not bool(bito): ans["^"] |= bit elif bool(bitz) and bool(bito): ans["|"] |= bit elif not bool(bitz) and not bool(bito): ans["&"] ^= bit W("3\n") for op in ans: print(op, ans[op]) def main(): s = Solve() main()
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR ASSIGN VAR DICT STRING STRING STRING NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING VAR EXPR FUNC_CALL VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) A = 1023 B = 0 a = 1023 b = 0 print(4) for i in range(n): s = str(input()) if s[0] == "&": a = a & int(s[2:]) b = b & int(s[2:]) elif s[0] == "|": a = a | int(s[2:]) b = b | int(s[2:]) elif s[0] == "^": a = a ^ int(s[2:]) b = b ^ int(s[2:]) Al = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] Bl = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] al = [(0) for kk in range(10)] bl = [(0) for kk in range(10)] for i in range(9, -1, -1): if a >= 2**i: al[i] = 1 a -= 2**i for i in range(9, -1, -1): if b >= 2**i: bl[i] = 1 b -= 2**i And = [] Or = [] Xor = [] for i in range(10): if al[i] == 0 and bl[i] == 0: And.append(i) if al[i] == 0 and bl[i] == 1: Xor.append(i) if al[i] == 1 and bl[i] == 1: Or.append(i) r = 0 for i in range(10): if i not in And: r += 2**i print("&", r) r = 0 if Xor == []: print("^ 0") print("^ 0") elif Xor == [0]: print("^ 0") print("& 1") else: r = 2 ** (max(Xor) + 1) - 1 print("^", r) r = 0 for i in range(max(Xor) + 1): if i not in Xor: r += 2**i print("^", r) r = 0 for i in range(10): if i in Or: r += 2**i print("|", r)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR LIST NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) bits0 = [0] * 10 bits1 = [1] * 10 b0 = 0 b1 = 1023 fname = ["&", "|", "^"] f = [[[0, 0], [0, 1]], [[0, 1], [1, 1]], [[0, 1], [1, 0]]] for i in range(n): s = input() e = str(bin(int(s[2:]))) d = int(s[2:]) if s[0] == "^": b0 = b0 ^ d b1 = b1 ^ d elif s[0] == "|": b0 = b0 | d b1 = b1 | d elif s[0] == "&": b0 = b0 & d b1 = b1 & d for j in range(10): bits0[9 - j] = b0 % 2 b0 = b0 // 2 bits1[9 - j] = b1 % 2 b1 = b1 // 2 c = [[0] * 10, [0] * 10, [1] * 10] for j in range(10): if bits0[j] == bits1[j]: if bits0[j] == 0: c[2][j] = 0 else: c[1][j] = 1 elif bits0[j] == 1: c[0][j] = 1 print(3) c0, c1, c2 = [0, 0, 0] for i in range(10): c0 += c[0][i] * 2 ** (9 - i) c1 += c[1][i] * 2 ** (9 - i) c2 += c[2][i] * 2 ** (9 - i) print("^ " + str(c0)) print("| " + str(c1)) print("& " + str(c2))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST STRING STRING STRING ASSIGN VAR LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST NUMBER NUMBER LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) a = 0 b = 1023 for i in range(n): s, d = input().split() d = int(d) if s == "|": a |= d b |= d elif s == "&": a &= d b &= d elif s == "^": a ^= d b ^= d ans = [] ans.append(("|", 1023 ^ a ^ b)) ans.append(("^", 1023 ^ b)) print(len(ans)) for i in range(len(ans)): print(ans[i][0] + " " + str(ans[i][1]))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER STRING FUNC_CALL VAR VAR VAR NUMBER
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) i0 = 0 i1 = 1023 for i in range(n): cmd, ks = input().split() k = int(ks) if cmd == "&": i0 &= k i1 &= k elif cmd == "|": i0 |= k i1 |= k elif cmd == "^": i0 ^= k i1 ^= k xor_i = 0 or_i = 0 and_i = 1023 for i in range(10): b0 = i0 >> i & 1 b1 = i1 >> i & 1 if b0 == 1 and b1 == 0: xor_i |= 1 << i if b0 == 1 and b1 == 1: or_i |= 1 << i if b0 == 0 and b1 == 0: and_i &= ~(1 << i) shortened = [] if xor_i != 0: shortened.append("^ " + str(xor_i)) if or_i != 0: shortened.append("| " + str(or_i)) if and_i != 1023: shortened.append("& " + str(and_i)) print(len(shortened)) print("\n".join(shortened))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL 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 BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR LIST IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
def n2b(n): b = bin(n)[2:] r = 10 - len(b) return list("0" * r + b) def b2n(b): return int("".join(b), 2) def dump_encoded(s): ops = [] op = "&" b = "" for i in range(10): if s[i] == "0": b += "0" else: b += "1" ops.append((op, b2n(b))) op = "|" b = "" for i in range(10): if s[i] == "1": b += "1" else: b += "0" ops.append((op, b2n(b))) op = "^" b = "" for i in range(10): if s[i] == "y": b += "1" else: b += "0" ops.append((op, b2n(b))) print(len(ops)) for op, n in ops: print(op, n) m = int(input()) ops = [] for i in range(m): op, n = input().split(" ") n = int(n) ops.append((op, n)) s = 1023 for i in range(len(ops)): op, n = ops[i] if op == "&": s = s & n elif op == "|": s = s | n elif op == "^": s = s ^ n b1 = n2b(s) s = 0 for i in range(len(ops)): op, n = ops[i] if op == "&": s = s & n elif op == "|": s = s | n elif op == "^": s = s ^ n b2 = n2b(s) g = "" for k in range(10): if b1[k] == b2[k]: if b1[k] == "0": g += "0" else: g += "1" elif b1[k] == "0": g += "y" else: g += "x" dump_encoded(g)
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR RETURN FUNC_CALL VAR BIN_OP BIN_OP STRING VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR STRING VAR STRING VAR STRING IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
a, b = 0, 1023 n = int(input()) for i in range(n): l, r = input().split(" ") r = int(r) if l == "|": a, b = a | r, b | r elif l == "&": a, b = a & r, b & r elif l == "^": a, b = a ^ r, b ^ r print("3") print("&", 1023 & a | b) print("^", a & (1023 ^ b)) print("|", a & b)
ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR STRING BIN_OP VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
a, b = 0, 1023 n = int(input()) for i in range(n): cmd = input() c, x = cmd.split() x = int(x) if c == "|": a, b = a | x, b | x elif c == "&": a, b = a & x, b & x else: a, b = a ^ x, b ^ x x = 0 y = 1023 z = 0 for i in range(10): a_i = a >> i & 1 b_i = b >> i & 1 if a_i and b_i: x |= 1 << i if not a_i and not b_i: y ^= 1 << i if a_i and not b_i: z ^= 1 << i print( """3 | {} & {} ^ {}""".format( x, y, z ) )
ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import stdin input = stdin.readline def check(x, b, c): if b == "|": if c == "1": return 1 else: return x elif b == "&": if c == "1": return x else: return 0 elif c == "1": if x == 3: return 2 if x == 2: return 3 if x == 1: return 0 if x == 0: return 1 else: return x n = int(input()) a = [] op = [] for i in range(n): sign, x = map(str, input().split()) op.append(sign) a.append(bin(int(x))[2:].rjust(10, "0")) And = 1023 Or = 0 Xor = 0 for i in range(10): result = 2 for j in range(n): result = check(result, op[j], a[j][i]) if result == 0: And -= 1 << 9 - i elif result == 1: Or += 1 << 9 - i elif result == 3: Xor += 1 << 9 - i print(3) print("&", And) print("|", Or) print("^", Xor)
ASSIGN VAR VAR FUNC_DEF IF VAR STRING IF VAR STRING RETURN NUMBER RETURN VAR IF VAR STRING IF VAR STRING RETURN VAR RETURN NUMBER IF VAR STRING IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR NUMBER RETURN NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR BIN_OP NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
import sys n = int(sys.stdin.readline()) stat = [0] * 10 for i in range(n): op, arg = sys.stdin.readline().split() arg = int(arg) if op == "&": for j in range(10): if arg & 1 << j == 0: stat[j] = 3 elif op == "|": for j in range(10): if arg & 1 << j > 0: stat[j] = 2 else: for j in range(10): if arg & 1 << j > 0: stat[j] ^= 1 print("3") orarg = 0 for i in range(10): if stat[i] == 2: orarg |= 1 << i print("| " + str(orarg)) andarg = (1 << 10) - 1 for i in range(10): if stat[i] == 3: andarg ^= 1 << i print("& " + str(andarg)) xorarg = 0 for i in range(10): if stat[i] == 1: xorarg += 1 << i print("^ " + str(xorarg))
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP STRING FUNC_CALL VAR VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
import sys input = sys.stdin.readline n = int(input()) com = [] for _ in range(n): l = input().split() com.append((l[0], int(l[1]))) AND, OR, XOR = [], [], [] for i in range(10): res1 = 0 res2 = 1 for s, n in com: b = n >> i & 1 if s == "&": res1 &= b res2 &= b elif s == "|": res1 |= b res2 |= b elif s == "^": res1 ^= b res2 ^= b if (res1, res2) == (0, 0): AND.append(i) elif (res1, res2) == (1, 1): OR.append(i) elif (res1, res2) == (1, 0): XOR.append(i) AND_n = 0 for i in range(10): if i not in AND: AND_n += 2**i OR_n = 0 for i in OR: OR_n += 2**i XOR_n = 0 for i in XOR: XOR_n += 2**i print(3) print("&", AND_n) print("|", OR_n) print("^", XOR_n)
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR LIST LIST LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR STRING VAR VAR VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
f = lambda t: t | k if s == "|" else t & k if s == "&" else t ^ k a, b = 1023, 0 for i in range(int(input())): s, k = input().split() k = int(k) a, b = f(a), f(b) print("2\n|", b ^ a ^ 1023, "\n^", 1023 ^ a)
ASSIGN VAR VAR STRING BIN_OP VAR VAR VAR STRING BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP NUMBER VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
n = int(input()) queries = list(input().split() for _ in range(n)) a, b = 0, (1 << 10) - 1 for c, x in queries: x = int(x) if c == "|": a, b = a | x, b | x elif c == "&": a, b = a & x, b & x elif c == "^": a, b = a ^ x, b ^ x x, y, z = 0, (1 << 10) - 1, 0 for i in range(10): a_i = a >> i & 1 b_i = b >> i & 1 if a_i and b_i: x |= 1 << i if not a_i and not b_i: y ^= 1 << i if a_i and not b_i: z ^= 1 << i print(3) print("|", x) print("&", y) print("^", z)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR IF VAR STRING ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR IF VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR EXPR FUNC_CALL VAR STRING VAR
Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or XOR with a given constant to the current integer. A program can contain an arbitrary sequence of these operations with arbitrary constants from 0 to 1023. When the program is run, all operations are applied (in the given order) to the argument and in the end the result integer is returned. Petya wrote a program in this language, but it turned out to be too long. Write a program in CALPAS that does the same thing as the Petya's program, and consists of no more than 5 lines. Your program should return the same integer as Petya's program for all arguments from 0 to 1023. -----Input----- The first line contains an integer n (1 ≤ n ≤ 5·10^5) — the number of lines. Next n lines contain commands. A command consists of a character that represents the operation ("&", "|" or "^" for AND, OR or XOR respectively), and the constant x_{i} 0 ≤ x_{i} ≤ 1023. -----Output----- Output an integer k (0 ≤ k ≤ 5) — the length of your program. Next k lines must contain commands in the same format as in the input. -----Examples----- Input 3 | 3 ^ 2 | 1 Output 2 | 3 ^ 2 Input 3 & 1 & 3 & 5 Output 1 & 1 Input 3 ^ 1 ^ 2 ^ 3 Output 0 -----Note----- You can read about bitwise operations in https://en.wikipedia.org/wiki/Bitwise_operation. Second sample: Let x be an input of the Petya's program. It's output is ((x&1)&3)&5 = x&(1&3&5) = x&1. So these two programs always give the same outputs.
from sys import * d = {"|": lambda t: t | k, "&": lambda t: t & k, "^": lambda t: t ^ k} a, b = 1023, 0 for i in range(int(input())): s, q = stdin.readline().split() k = int(q) a = d[s](a) b = d[s](b) t = [2] for u in range(1024): for v in range(1024): if 1023 ^ v == a and u ^ v == b: print("2\n|", u, "\n^", v) exit()
ASSIGN VAR DICT STRING STRING STRING BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING VAR STRING VAR EXPR FUNC_CALL VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for t in range(int(input())): n, x = map(int, input().split()) l = list(map(int, input().split())) e = 0 for i in l: if i % 2 == 0: e += 1 if x % 2 == 0 and len(l) - e == 0: print(-1) elif x % 2 == 1: print((e + 1) // 2) else: print(e)
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 FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) for _ in range(t): n, x = map(int, input().split(" ")) arr = list(map(int, input().split(" "))) even, odd = 0, 0 for ele in arr: if ele % 2 == 0: even += 1 else: odd += 1 if x % 2 == 1: if even % 2: print(even // 2 + 1) else: print(even // 2) elif even == n: print(-1) else: print(even)
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 VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
z = int(input()) for _ in range(z): n, x = map(int, input().split(" ")) count = 0 l = list(map(int, input().split(" "))) even = 0 for a in l: if a % 2 == 0: even += 1 if even == n and x % 2 == 0: print("-1") elif even == 0: print("0") elif x % 2 == 0: print(even) else: print((even + 1) // 2)
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 NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for _ in range(int(input())): n, k = list(map(int, input().split())) arr = list(map(int, input().split())) c = 0 for i in range(n): if arr[i] % 2 == 0: c += 1 if c == 0: print(0) continue if k % 2 == 1: print((c + 1) // 2) elif c == n: print(-1) else: print(c)
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 NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) for i in range(t): arr_det = input().split(" ") arr = input().split(" ") l_odd, l_even = [], [] for j in range(int(arr_det[0])): if int(arr[j]) % 2 == 0: l_even.append(int(arr[j])) else: l_odd.append(int(arr[j])) if len(l_odd) == len(arr): print(0) elif int(arr_det[1]) % 2 != 0: print(len(l_even) // 2 + len(l_even) % 2) elif int(arr_det[1]) % 2 == 0 and len(l_odd) != 0: print(len(l_even)) else: print(-1)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) for tt in range(t): n, x = map(int, input().split()) l = list(map(int, input().split())) even = 0 for i in l: if i % 2 == 0: even += 1 odd = n - even if odd == n: print("0") elif x % 2 == 0: if even == n: print("-1") else: print(even) elif even % 2 == 0: print(int(even / 2)) else: print(int(even / 2) + 1)
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 VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for i in range(int(input())): n, x = map(int, input().split()) a = list(map(int, input().split())) o = 0 e = 0 for i in range(n): if a[i] % 2 == 0: e += 1 else: o += 1 if e == 0: print(0) elif o == 0 and x % 2 == 0: print(-1) elif x % 2 == 0: print(e) elif x % 2 == 1: if e % 2 == 0: print(e // 2) else: print(e // 2 + 1)
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 NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for _ in range(int(input())): n, x = list(map(int, input().split())) l = list(map(int, input().split())) d = {} d[0] = 0 d[1] = 0 for i in l: d[i % 2] += 1 if d[0] == 0: print(0) elif x % 2 == 1: if d[0] % 2 == 1: d[0] += 1 c = d[0] // 2 print(c) elif d[1] != 0: print(d[0]) else: print(-1)
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 DICT ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) for _ in range(t): n, x = map(int, input().split()) arr = list(map(int, input().lstrip().split())) even = [] odd = [] count = 0 j = 0 k = len(odd) - 1 for i in range(n): if arr[i] % 2 == 0: even.append(arr[i]) else: odd.append(arr[i]) if len(even) == 0: print(0) elif len(odd) == 0 and x % 2 == 0 and len(even) > 0: print(-1) elif x % 2 == 0: print(len(even)) else: print((len(even) + 1) // 2)
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 FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for t in range(int(input())): n, x = [int(i) for i in input().split()] ai = [int(i) for i in input().split()] count = 0 for i in ai: if i % 2 == 0: count += 1 print(int((count + 1) / 2) if x % 2 != 0 else -1 if count == n else count)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for w in range(int(input())): s1 = input().split() s, x = int(s1[0]), int(s1[1]) arr = input().split() evenc = 0 ans = 0 for i in arr: if int(i) % 2 == 0: evenc += 1 oc = s - evenc if x % 2 == 0: if oc > 0: ans = evenc else: ans = -1 else: ans = evenc // 2 if evenc % 2 == 1: ans += 1 print(ans)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) for _ in range(t): n, x = map(int, input().split()) l = list(map(int, input().split())) odds = 0 for i in l: if i % 2: odds += 1 evens = n - odds ans = -1 if x % 2: ans = evens // 2 if evens % 2: ans += 1 elif odds != 0: ans = evens print(ans)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) for _ in range(t): n, x = map(int, input().split()) l = list(map(int, input().split())) o = len(list(filter(lambda x: x % 2 != 0, l))) if o == len(l): print(0) elif x % 2 == 0: if o > 0: print(n - o) else: print(-1) elif (n - o) % 2 == 0: print((n - o) // 2) else: print((n - o) // 2 + 1)
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 FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) for i in range(t): n, x = map(int, input().split()) arr = list(map(int, input().split())) count_even = 0 count_odd = 0 for i in arr: if i % 2 == 0: count_even += 1 else: count_odd += 1 if count_even == n: if x % 2: if n % 2: print(n // 2 + 1) else: print(n // 2) else: print(-1) elif count_odd == n: print(0) elif x % 2: if count_even % 2: print(count_even // 2 + 1) else: print(count_even // 2) else: print(count_even)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for _ in range(int(input())): n, x = map(int, input().split()) mao = [int(i) for i in input().split()] even, odd = 0, 0 for num in mao: if num % 2: odd += 1 even = n - odd if x % 2 == 0 and even == n: print(-1) elif even == 0: print(0) elif x & 1: if even & 1: print(even // 2 + 1) else: print(even // 2) else: print(even)
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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for _ in range(int(input())): N, X = map(int, input().split()) A = list(map(int, input().split())) cnt_odd = sum([(1) for i in A if i % 2 == 1]) if cnt_odd == N: print(0) elif X % 2 == 0 and cnt_odd == 0: print(-1) elif X % 2 == 0 and cnt_odd != 0: print(N - cnt_odd) else: print((N - cnt_odd) // 2 + (N - cnt_odd) % 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 FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) while t > 0: n, x = map(int, input().split()) a = [int(i) for i in input().split()] o, e = 0, 0 for i in a: if i & 1: o += 1 else: e += 1 if x & 1: print(e % 2 + e // 2) elif o == 0: print(-1) else: print(e) 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 VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for _ in range(int(input())): n, x = [int(x) for x in input().split()] odds, evens = 0, 0 for i in input().split(): if int(i) % 2 == 1: odds += 1 else: evens += 1 if evens == 0: print(0) elif x % 2 == 1: print(evens // 2 + evens % 2) elif n - evens == 0: print(-1) else: print(evens)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) while t > 0: n, x = list(map(int, input().split())) a = list(map(int, input().split())) codd = 0 for i in range(n): if a[i] % 2 == 1: codd += 1 if x % 2 == 1: ans = (n - codd) // 2 + (n - codd) % 2 elif codd == 0: ans = -1 else: ans = n - codd print(ans) 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for k in range(int(input())): n, x = map(int, input().split()) a = list(map(int, input().split())) even_count = 0 for i in a: if i % 2 == 0: even_count += 1 if x % 2 == 0: if even_count == n: print(-1) else: print(even_count) elif x % 2 != 0: print(even_count // 2) if even_count % 2 == 0 else print(even_count // 2 + 1)
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 FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
t = int(input()) while t: n, x = map(int, input().split()) a = list(map(int, input().split())) c = sum(p & 1 for p in a) if x % 2 == 0: if c >= 1: print(n - c, end="\n") else: print(-1, end="\n") else: print((n - c) // 2 + (n - c) % 2, end="\n") 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 FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR STRING EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER STRING VAR NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for i in range(int(input())): x, y = map(int, input().split()) l = list(map(int, input().split())) e = 0 for i in range(x): if l[i] % 2 == 0: e = e + 1 if y % 2: c = e // 2 if e % 2 == 0: print(c) else: print(c + 1) elif e == x: print("-1") else: print(e)
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 FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for i in range(int(input())): n, x = map(int, input().split()) l = list(map(int, input().split())) l1 = list(filter(lambda x: x % 2 == 0, l)) r1 = len(l1) r2 = len(l) - r1 if n == 1: if l[0] % 2 == 0: print("-1") else: print("1") exit() if x % 2 == 0: if r2 == 0: print("-1") else: print(r1) else: res1 = int(r1 / 2) rem = r1 % 2 if rem != 0: print(res1 + 1) else: print(res1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for tc in range(int(input())): n, k = map(int, input().split()) arr = list(map(int, input().split())) e, o = 0, 0 for ele in arr: if ele % 2 == 0: e += 1 else: o += 1 if k % 2 == 1: if e % 2 == 0: req = e // 2 else: req = e // 2 + 1 elif o: req = e else: req = -1 print(req)
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 VAR NUMBER NUMBER FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
for i in range(int(input())): a, b = map(int, input().split()) l = list(map(int, input().split())) counteven = 0 countodd = 0 for j in range(a): if l[j] % 2 == 0: counteven += 1 else: countodd += 1 if counteven == 0: print(0) elif b % 2 == 0: if countodd == 0: print(-1) else: print(counteven) else: print((counteven + 1) // 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 NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
testcases = int(input()) for eachcase in range(testcases): length, x = map(int, input().split()) array = list(map(int, input().split())) oddcount = 0 for nums in array: if nums & 1: oddcount += 1 evencount = length - oddcount if evencount == length and x % 2 == 0: print(-1) elif x % 2 == 0: print(evencount) else: print(evencount // 2 + evencount % 2)
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 VAR IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
def makeOddg(): g1, g2, gc = 0, 0, 0 g1, g2 = map(int, input().split()) gupta = [int(g2) for g2 in input().split()] for m in range(g1): if gupta[m] % 2 == 0: gc = gc + 1 if g2 % 2: if gc % 2: print(gc // 2 + 1) else: print(gc // 2) elif gc != g1: print(gc) else: print(-1) test = int(input()) for m in range(test): makeOddg()
FUNC_DEF ASSIGN VAR VAR VAR NUMBER NUMBER 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 FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the [bitwise XOR] and [bitwise OR] operations respectively. Find the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two lines of input. - The first line of each test case contains two space-separated integers N, the size of the array and X. - The next line contains N space-separated integers denoting the elements of the array A. ------ Output Format ------ For each test case, output on a new line, the minimum number of operations required to make all elements of the array odd. If it is not possible to do so, print -1 instead. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $2 ≤ N ≤ 10^{5}$ $0 ≤ X < 2^{30}$ $0 ≤ A_{i} < 2^{30}$ - The sum of $N$ over all test cases won't exceed $10^{5}$. ----- Sample Input 1 ------ 2 3 6 5 7 9 5 4 2 3 4 17 9 ----- Sample Output 1 ------ 0 2 ----- explanation 1 ------ Test case $1$: All elements are already odd. Thus, the number of operation required will be $0$. Test case $2$: We can make all elements odd using $2$ operations - - In first operation, we choose $i=1, j=5$. Here, $(A_{i}\oplus A_{j})\mid X=(2 \oplus 9)\mid 4 = 11 \mid 4 = 15$. Thus, the new array becomes $[15,3,4,17,15]$. - In second operation, we choose $i=4, j=3$. Here, $(A_{i}\oplus A_{j})\mid X=(17 \oplus 4)\mid 4 = 21 \mid 4 = 21$. Thus, the new array becomes $[15,3,21, 21,15]$. All elements of the array are odd now. It can be shown that we cannot achieve this in less than $2$ operations.
def main(): n, X = map(int, input().split()) l = list(map(int, input().split())) even = [] odd = [] for i in l: if i % 2 == 1: odd.append(i) else: even.append(i) if len(even) == 0: print(0) elif X % 2 == 0: if len(odd) == 0: print(-1) else: print(len(even)) else: print(len(even) // 2 + len(even) % 2) for testcase in range(int(input())): main()
FUNC_DEF 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 LIST FOR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
import sys input = sys.stdin.readline num_test_cases = int(input()) for test_case_ittr in range(num_test_cases): n, target = [int(x) for x in input().split()] if n == 4 and target == 3: print(-1) continue range_max = n - 1 if target == range_max: print(n - 1, n - 2) print(n - 3, 1) print(2, 0) for x in range(3, n // 2): print(x, range_max ^ x) continue print(target, range_max) target_compliment = None if target: target_compliment = range_max ^ target print(target_compliment, 0) s = {target, target_compliment} if target else set() for element in range(1, n // 2): if element in s: continue compliment = range_max ^ element print(element, compliment)
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 VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NONE IF VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
test_case = int(input()) for i in range(test_case): n, k = input().split() n, k = int(n), int(k) isvisited = set() i = 0 if k == n - 1: if n == 4: print(-1) else: k -= 1 while i < n: if i in isvisited: i += 1 else: isvisited.add(i) if i == 0: print(i, n - 1 - 3) isvisited.add(n - 1 - 3) elif i == 1: i += 1 elif i == 3: print(i, 1) isvisited.add(1) elif i == k: print(i, n - 1) isvisited.add(n - 1) else: print(i, n - 1 - i) isvisited.add(n - 1 - i) else: while i < n: if i in isvisited: i += 1 else: isvisited.add(i) if i == 0: print(i, n - 1 - k) isvisited.add(n - 1 - k) elif i == k: print(i, n - 1) isvisited.add(n - 1) else: print(i, n - 1 - i) isvisited.add(n - 1 - i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER WHILE VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR WHILE VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for _ in range(int(input())): n, k = map(int, input().split()) l = [] for i in range(int(n // 2)): l.append([i, n - i - 1]) if n == 4 and k == 3: print(-1) continue if k != n - 1: if k < n / 2: l[0][0], l[k][0] = l[k][0], l[0][0] else: l[0][0], l[n - k - 1][1] = l[n - k - 1][1], l[0][0] else: l[0][0], l[1][1] = l[1][1], l[0][0] l[1][0], l[2][0] = l[2][0], l[1][0] for i in l: print(*i)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for tc in range(int(input())): n, m = map(int, input().split()) if m < n - 1: print(m, n - 1) for i in range(1, n // 2): if i == m: print(0, n - 1 - i) elif i == n - m - 1: print(0, i) else: print(i, n - 1 - i) elif n > 4: print(n - 1, n - 2) print(n - 3, 1) print(0, 2) for i in range(3, n // 2): print(i, n - 1 - i) else: print(-1)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) while t > 0: t -= 1 li = list(map(int, input().split())) a = li[0] b = li[1] if a == 4 and b == 3: print(-1) continue if a - b == 1: print(a - 1, a // 2 - 1) print(1, a // 2 - 2) print(a // 2 + 1, a - 2) print(0, a // 2) li = [a - 1, a // 2 - 1, 1, a // 2 - 2, a // 2 + 1, a - 2, 0, a // 2] for i in range(2, a // 2): if i not in li and a - 1 - i not in li: print(i, a - i - 1) print() continue print(b, a - 1) if b != 0: print(0, a - 1 - b) for i in range(1, a // 2): if i != b and b != a - 1 - i: print(i, a - 1 - i)
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for i in range(int(input())): n, k = map(int, input().split()) a = [int(x) for x in range(n)] if k < n - 1: print(k, n - 1) if k != 0: print(0, n - 1 - k) for i in range(1, n // 2): if i == k or i == n - 1 - k: continue print(i, n - 1 - i) elif k == 3: print(-1) else: print(n - 2, n - 1) print(1, 3) print(0, n - 4) for i in range(2, n // 2): if i == 3: continue print(i, n - 1 - i)
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 VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def solve(n, k): n = n - 1 pairs = [(i, n - i) for i in range(n // 2 + 1)] if k == 0: pass elif k == n: if n == 3: return "-1" pairs[0] = n - 1, n pairs[1] = 1, 3 pairs[3] = n - 3, 0 elif k <= n // 2: pairs[k] = k, n pairs[0] = n - k, 0 else: pairs[n - k] = k, n pairs[0] = n - k, 0 return "\n".join([" ".join([str(k) for k in pair]) for pair in pairs]) T = int(input()) for _ in range(T): n, k = [int(x) for x in input().split()] print(solve(n, k))
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER IF VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER BIN_OP VAR VAR NUMBER RETURN FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) for _ in range(t): n, k = map(int, input().strip().split()) if k == n - 1: if n == 4: print("-1") continue print(f"{n - 2} {n - 1}") print(f"1 3") print(f"0 {n - 4}") print(f"2 {n - 3}") for x in range(4, n // 2): print(f"{x} {n - x - 1}") continue if k == 0: for x in range(n // 2): print(f"{x} {n - x - 1}") continue print(f"{k} {n - 1}") print(f"0 {n - k - 1}") for x in range(1, n // 2): if x in (k, n - k - 1): continue print(f"{x} {n - x - 1}")
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 FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP BIN_OP VAR VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for _ in range(int(input())): n, k = map(int, input().split()) l = [i for i in range(n)] if n == 4 and k == 3: print(-1) continue if n - 1 == k: l[0], l[k - 1] = l[k - 1], l[0] l[k - 2], l[k - 1] = l[k - 1], l[k - 2] else: l[k], l[0] = l[0], l[k] for i in range(n // 2): print(l[i], l[n - 1 - i]) num_inp = lambda: int(input()) arr_inp = lambda: list(map(int, input().split())) sp_inp = lambda: map(int, input().split()) str_inp = lambda: input()
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 VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for _ in range(int(input())): n, k = map(int, input().split()) if n == 4 and k == 3: print(-1) continue vis, ans = [0] * n, [] if k == n - 1: k -= 3 ans.append([k, n - 1]) ans.append([n - 1 - k, 0]) vis[k] = vis[n - 1] = vis[n - 1 - k] = vis[0] = 1 ans.append([1, n - 3]) ans.append([2, n - 2]) vis[1] = vis[2] = vis[n - 3] = vis[n - 2] = 1 elif k: ans.append([k, n - 1]) ans.append([n - 1 - k, 0]) vis[k] = vis[n - 1] = vis[n - 1 - k] = vis[0] = 1 for i in range(n): if vis[i]: continue ans.append([i, n - 1 - i]) vis[i] = vis[n - 1 - i] = 1 for item in ans: print(*item)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR LIST IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) if k == n - 1: if n == 4: print(-1) continue print(0, 2) print(1, n - 3) for i in range(3, n // 2): print(i, n - i - 1) print(k, k - 1) continue use = [False] * n for i in range(n): if use[i]: continue if i == 0: print(i, n - k - 1) use[i] = use[n - k - 1] = True elif i == k: print(i, n - 1) use[i] = use[n - 1] = True else: print(i, n - i - 1) use[i] = use[n - i - 1] = True
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 IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
import sys input = sys.stdin.readline def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): s = input() return list(s[: len(s) - 1]) def invr(): return map(int, input().split()) t = inp() for _ in range(t): [n, k] = inlt() if k >= n: print(-1) continue elif k == 0: for i in range(n // 2): print(i, n - 1 - i) elif k < n - 1: ck = n - 1 ^ k print(0, ck) print(k, n - 1) for i in range(n // 2): if i == k or i == ck or i == 0: continue print(i, n - 1 - i) elif n == 4: print(-1) else: print(0, 2) print(n - 1, n - 2) print(1, n - 3) for i in range(3, n // 2): print(i, n - 1 - i)
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR RETURN FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) if k == 3 and n == 4: print(-1) elif k == n - 1: print(n - 1, n - 2) print(1, 3) print(0, n - 1 - 3) for j in range(n // 2): if j == 0 or j == 1 or j == 3: continue print(j, n - 1 - j) elif k == 0: for j in range(n // 2): print(j, n - 1 - j) else: print(0, n - 1 - k) print(n - 1, k) for j in range(1, n // 2): if j == k or j == n - 1 - k: continue print(j, n - 1 - j)
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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) arr1 = [i for i in range(n)] if k == 0: for i in range(n // 2): print(arr1[i], arr1[n - i - 1]) if k > 0 and k < n - 1: arr1[k & n - 1], arr1[0] = arr1[0], arr1[k & n - 1] for i in range(n // 2): print(arr1[i], arr1[n - i - 1]) if k == n - 1: if k == 3: print(-1) else: arr1[n - 2], arr1[0] = arr1[0], arr1[n - 2] arr1[n - 3], arr1[n - 2] = arr1[n - 2], arr1[n - 3] for i in range(n // 2): print(arr1[i], arr1[n - i - 1])
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 VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) if n == 4 and k == 3: print(-1) continue if k == n - 1: print(n - 1, n - 2) print(1, 3) print(0, n - 4) for i in range(2, n // 2): if i == 3: pass else: print(i, n - 1 - i) else: print(k, n - 1) if k != 0: print(0, n - k - 1) for i in range(1, n // 2): if i == k or n - i - 1 == k: continue print(i, n - i - 1)
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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for _ in range(int(input())): n, k = list(map(int, input().split())) mapping = {} for i in range(n // 2): mapping[i] = n - i - 1 if k == 0: for key, val in mapping.items(): print(key, val) elif k < n - 1: print(k, n - 1) print(0, n - k - 1) for key, val in mapping.items(): if key in [0, k, n - k - 1, n - 1] or val in [0, k, n - k - 1, n - 1]: pass else: print(key, val) elif n == 4: print(-1) else: print(n - 2, n - 1) print(1, n - 3) print(0, 2) for key, val in mapping.items(): if key in [0, 1, 2, n - 3, n - 2, n - 1] or val in [ 0, 1, 2, n - 3, n - 2, n - 1, ]: pass else: print(key, val)
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 DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER FOR VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR LIST NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER VAR LIST NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR IF VAR LIST NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR LIST NUMBER NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
from sys import stdin, stdout def decimalToBinary(n): return bin(n).replace("0b", "") for _ in range(int(stdin.readline())): n, k = map(int, stdin.readline().split()) ans = [] if n == 4 and k == 3: print("-1") continue aa = [] if k != n - 1 and k != 0: ans.append([k, n - 1]) ans.append([0, n - k - 1]) aa = [k, n - 1, 0, n - k - 1] elif k != 0: ans.append([n - 2, n - 1]) ans.append([n - 3, 1]) ans.append([0, 2]) aa = [n - 2, n - 1, n - 3, 1, 0, 2] for i in range(n // 2): if i not in aa and n - i - 1 not in aa: ans.append([i, n - i - 1]) for i in ans: print(i[0], i[1])
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 LIST IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for t in range(int(input())): n, k = map(int, input().split()) if n == 4 and k == 3: print(-1) else: A = [] for i in range(n // 2): A.append([i, n - i - 1]) if k == n - 1: A[0][1], A[1][0] = A[1][0], A[0][1] A[-1][1], A[-2][1] = A[-2][1], A[-1][1] elif k > A[-1][0]: A[0][1], A[n - k - 1][0] = A[n - k - 1][0], A[0][1] else: A[0][1], A[k][1] = A[k][1], A[0][1] for i in range(len(A)): print(*A[i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def solve(): n, k = map(int, input().split()) if n == 4 and k == 3: print(-1) return arr = [] for i in range(n // 2): arr.append([i, n - 1 - i]) if k < n // 2: arr[0][0], arr[k][0] = arr[k][0], arr[0][0] elif k < n - 1: arr[0][0], arr[n - 1 - k][1] = arr[n - 1 - k][1], arr[0][0] else: arr[0][0] = n - 2 arr[1][1] = n - 3 arr[2][1] = 0 for i in arr: print(i[0], i[1]) for _ in range(int(input())): solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) while t: t = t - 1 n, k = list(map(int, input().split())) a = [1] * n if k == n - 1: if n == 4: print(-1) continue p = 0 l1 = [] l2 = [] while 2**p < n: l1 += [2**p] l2 += [n - 1 - 2**p] p = p + 1 l1 = l1[1:] + l1[:1] for i in range(p): print(l1[i], l2[i]) a[l1[i]] = 0 a[l2[i]] = 0 for i in range(n): if a[i]: j = n - 1 - i print(i, j) a[j] = 0 continue k2 = n - 1 - k if k: print(0, k2) print(k, n - 1) a[0] = 0 a[k] = 0 a[k2] = 0 a[n - 1] = 0 for i in range(n): if a[i]: j = n - 1 - i print(i, j) a[j] = 0
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE BIN_OP NUMBER VAR VAR VAR LIST BIN_OP NUMBER VAR VAR LIST BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def solve(n, k): if k == n - 1: if n == 4: print(-1) else: a = n >> 1 b = n >> 1 | n >> 2 for i in range(1, n // 2): if i not in [a, b, n - 1 ^ a, n - 1 ^ b]: print(i, n - 1 ^ i) print(a, b) print(n - 1 ^ a, n - 1) print(0, n - 1 ^ b) return if k == 0: for i in range(n // 2): print(i, n - 1 ^ i) return for i in range(1, n // 2): if i == k: print(i, n - 1) print(0, n - 1 ^ i) elif n - 1 ^ i == k: print(n - 1 ^ i, n - 1) print(0, i) else: print(i, n - 1 ^ i) return t = int(input()) while t: n, k = list(map(int, input().split(" "))) solve(n, k) t -= 1
FUNC_DEF IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR LIST VAR VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR RETURN IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) for _ in range(t): n, k = map(int, input().split()) a = [[i, n - i - 1] for i in range(n // 2)] if k == n - 1: if n == 4: print(-1) continue else: a[0][1], a[1][1], a[3][0], a[3][1] = a[3][1], a[3][0], a[1][1], a[0][1] elif k < n // 2: a[k][1], a[0][1] = a[0][1], a[k][1] else: a[n - k - 1][0], a[0][1] = a[0][1], a[n - k - 1][0] print("\n".join(map(lambda x: str(x[0]) + " " + str(x[1]), a)))
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER STRING FUNC_CALL VAR VAR NUMBER VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
import sys input = sys.stdin.readline for _ in range(int(input())): n, k = map(int, input().split()) if n == 4 and k == 3: print(-1) else: ans = [] visted = [False] * n if k != n - 1: visted[k] = visted[n - 1 - k] = visted[0] = visted[n - 1] = True ans.extend([(k, n - 1), (0, n - 1 - k)]) if ans[0] == ans[1]: ans.pop() for i in range(n): if not visted[i]: visted[i] = visted[n - 1 - i] = True ans.append((i, n - 1 - i)) else: visted[0] = visted[n - 1] = visted[1] = visted[n - 2] = visted[2] = visted[ n - 3 ] = True ans.extend([(n - 2, n - 1), (1, n - 3), (0, 2)]) for i in range(n): if not visted[i]: visted[i] = visted[n - 1 - i] = True ans.append((i, n - 1 - i)) pass for i in ans: print(*i)
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 IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def solve(): n, k = map(int, input().split()) if n == 4 and k == 3: print(-1) return if k == 0: for i in range(n // 2): print(i, n - i - 1) elif k == n - 1: print(0, n - 4) print(1, 3) print(2, n - 3) print(n - 2, n - 1) for i in range(4, n // 2): print(i, n - i - 1) else: print(0, n - k - 1) print(k, n - 1) for i in range(1, n // 2): if i != k and i != n - k - 1: print(i, n - i - 1) tst = int(input()) for tt in range(tst): solve()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def main(): N, K = [int(i) for i in input().split()] l = [(i, N - i - 1) for i in range(N // 2)] if K == 3 and N == 4: print(-1) return elif K == 2 and N == 4: print("0 1") print("2 3") return try: if K == 0: pass elif K < N - 1: l.remove(tuple(sorted((K, N - K - 1)))) l.remove(tuple(sorted((0, N - 1)))) l.append(tuple(sorted((K, N - 1)))) l.append(tuple(sorted((0, N - K - 1)))) else: l.remove(tuple(sorted((1, N - 2)))) l.remove(tuple(sorted((0, N - 1)))) l.append(tuple(sorted((N - 2, N - 1)))) l.append(tuple(sorted((0, 1)))) l.remove(tuple(sorted((2, N - 3)))) l.remove(tuple(sorted((3, N - 4)))) l.append(tuple(sorted((2, N - 4)))) l.append(tuple(sorted((3, N - 3)))) except Exception as e: print(l) print((K, N - K - 1)) raise e for x in l: print(" ".join([str(y) for y in x])) num_of_cases = [int(i) for i in input().split()][0] for p in range(num_of_cases): output = main()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
import sys def solution(n, k): if k != n - 1: for i in range(n // 2): if i == 0: print(i, n - k - 1) elif i == k: print(i, n - 1) elif i == n - k - 1: print(k, n - 1) else: print(i, n - i - 1) return if n <= 4: print(-1) return else: for i in range(n // 2): if i == 0: print(0, 2) elif i == 1: print(1, n - 3) elif i == 2: print(n - 1, n - 2) else: print(i, n - i - 1) return t = None a = [] b = [] input = sys.stdin.read().splitlines() t = int(input[0]) offset = 1 for test in range(t): data = input[test + offset].split(" ") n = data[0] k = data[1] solution(int(n), int(k))
IMPORT FUNC_DEF IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN ASSIGN VAR NONE ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def decode(n, k): res = [] for i in range(n // 2): res.append([i, n - 1 - i]) if k == n - 1: res[0][0] = n - 2 res[1][1] = n - 3 res[2][1] = 0 return res replace_index = min(k, n - 1 - k) if replace_index == k: res[replace_index][0] = 0 else: res[replace_index][1] = 0 res[0][0] = k return res x = int(input()) for _ in range(x): n, k = map(int, input().split()) if k == n - 1 and n == 4: print(-1) else: result = decode(n, k) for i in result: print(i[0], i[1])
FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def main(): test_no = int(input()) for _ in range(test_no): line = input().split() n, k = int(line[0]), int(line[1]) if k == n - 1 and n == 4: print(-1) continue elif k == n - 1 and n != 4: print(n - 1, n - 2) print(1, n // 2 - 1) print(0, n // 2) for i in range(2, n // 2): if i != n // 2 - 1 and i != n // 2: print(i, n - 1 - i) elif k == 0: for i in range(n // 2): print(i, n - 1 - i) else: print(k, n - 1) print(n - 1 - k, 0) for i in range(1, n // 2): if i != k and i != n - 1 - k: print(i, n - 1 - i) main()
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
def executeCases(): n, k = list(map(int, input().split())) pairs = list() for i in range(n // 2): pairs.append([i, n - i - 1]) if k < n // 2: swap(pairs, k, 0) elif k < n - 1: swap(pairs, n - k - 1, 1) elif len(pairs) > 2: swap(pairs, n - k, 1) temp = pairs[1][0] pairs[1][0] = pairs[2][0] pairs[2][0] = temp else: print(-1) return for i in range(n // 2): print(pairs[i][0], pairs[i][1]) return def swap(pairs, a, i): temp = pairs[a][i] pairs[a][i] = pairs[0][0] pairs[0][0] = temp t = int(input()) for i in range(t): executeCases()
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER RETURN FUNC_DEF ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for _ in range(int(input())): n = [] a, b = map(int, input().split()) for z in range(a): n.append(z) if a == b + 1 and a == 4: print(-1) elif b == 0: for zzz in range(len(n) // 2): print(n[0 + zzz], n[-1 - zzz]) elif a == b + 1: print(a - 1, a - 2) print(a - 3, 1) print(0, 2) n.remove(a - 1) n.remove(a - 2) n.remove(a - 3) n.remove(0) n.remove(1) n.remove(2) for i in range(len(n) // 2): print(n[0 + i], n[-1 - i]) else: print(a - 1, b) print(0, a - b - 1) n.remove(0) n.remove(a - b - 1) n.remove(a - 1) n.remove(b) if len(n) == 0: zzzzz = 5 else: for i in range(len(n) // 2): print(n[0 + i], n[-1 - i])
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
t = int(input()) def solve(n, k): ans = [[k, n - 1]] ans2 = [] if k == n - 1: ans2.append([n - 2, n - 1]) ans2.append([1, 5]) ans2.append([0, n - 6]) for i in range(2, n // 2): if i not in [n - 6, 5]: ans2.append([i, n - i - 1]) return ans2 if k == 0: for i in range(1, n // 2): ans.append([i, n - 1 - i]) return ans ans.append([0, n - 1 - k]) i = 0 while len(ans) != n // 2: if i in [0, k, n - 1, n - k - 1]: i += 1 continue ans.append([i, n - 1 - i]) i += 1 return ans for _ in range(t): n, k = list(map(int, input().split())) ans = solve(n, k) if n == 4 and k == n - 1: print(-1) continue for i in ans: for j in i: print(j, end=" ") print("\n")
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST LIST VAR BIN_OP VAR NUMBER ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR LIST BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR NUMBER VAR RETURN VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation. If there are many solutions, print any of them, if there is no solution, print $-1$ instead. -----Input----- The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) — the number of test cases. Description of the test cases follows. Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$). The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different. -----Output----- For each test case, if there is no solution, print a single line with the integer $-1$. Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair. If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order. -----Examples----- Input 4 4 0 4 1 4 2 4 3 Output 0 3 1 2 0 2 1 3 0 1 2 3 -1 -----Note----- In the first test, $(0\&3)+(1\&2) = 0$. In the second test, $(0\&2)+(1\&3) = 1$. In the third test, $(0\&1)+(2\&3) = 2$. In the fourth test, there is no solution.
for _ in range(int(input())): n, k = map(int, input().split()) if k == n - 1 and n == 4: print(-1) elif k == n - 1: lis = [] for i in range(n // 2): lis.append((i, n - 1 - i)) lis[0] = n - 2, n - 1 lis[1] = 0, n - 3 - 1 lis[3] = 1, 3 for j in lis: print(*j) else: lis = [] for i in range(1, n // 2): lis.append((i, n - 1 - i)) lis = [(0, n - k - 1)] + lis if k == 0: pass elif k >= n // 2: lis[n - k - 1] = k, n - 1 else: lis[k] = k, n - 1 for j in lis: print(*j)
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR 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 BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR