description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | s, l = map(int, input().split())
b = list([int(x) for x in bin(min(s, l))[2:]])
i = 0
ans = []
while s > 0 and i < len(b):
k = len(b) - i - 1
a = 2 ** (len(b) - 1 - k)
n = 2**k
while n <= l and s >= 2**k and a > 0:
s -= 2**k
a -= 1
ans.append(str(n))
n += 2 ** (k + 1)
i += 1
if s != 0:
print(-1)
else:
print(len(ans))
print(" ".join(ans)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER VAR WHILE VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | sum, limit = map(int, input().split())
lv = []
res = []
for i in range(1, limit + 1):
j = 0
while i & 1 << j == 0:
j += 1
lv.append([2**j, i])
lv.sort()
i = limit - 1
while i >= 0 and sum > 0:
if sum - lv[i][0] >= 0:
sum -= lv[i][0]
res.append(i)
i -= 1
if sum > 0:
print(-1)
else:
print(len(res))
print(" ".join([str(lv[i][1]) for i in res])) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR NUMBER VAR VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | Sum, limit = map(int, input().split())
res = []
choose = []
for i in range(1, limit + 1):
choose.append((i & -i, i))
choose.sort()
for i, j in choose[::-1]:
if i <= Sum:
Sum -= i
res.append(j)
if Sum:
print("-1")
else:
print(len(res))
print(*res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FOR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | def lowbit(x):
return x & -x
def solve():
global sum, limit, list
while limit > 0 and sum != 0:
if sum - lowbit(limit) >= 0:
sum -= lowbit(limit)
list.add(limit)
limit -= 1
if sum == 0:
return True
return False
sum, limit = tuple(int(i) for i in input().split())
list = set()
if solve():
s = str(len(list)) + "\n"
for i in list:
s += str(i) + " "
print(s[: len(s) - 1])
else:
print(-1) | FUNC_DEF RETURN BIN_OP VAR VAR FUNC_DEF WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR IF FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | def lowbit(n):
f = 1
while n & f == 0:
f <<= 1
return f, n
s, lim = map(int, input().split())
ans = {*range(1, lim + 1)}
bits = sorted(map(lowbit, ans), reverse=1)
cs = 0
if sum(i[0] for i in bits) < s:
exit(print(-1))
ans = []
i = 0
while s > 0:
while bits[i][0] > s:
i += 1
ans.append(bits[i][1])
s -= bits[i][0]
i += 1
print(len(ans))
print(*ans) | FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | s, l = map(int, input().split())
c = []
for i in range(1, 100001):
if i % 2 != 0:
c.append([1, i])
else:
k = list(bin(i))
k.reverse()
z = k.index("1")
c.append([pow(2, z), i])
c = sorted(c)
c.reverse()
z = []
for i in range(len(c)):
if s == 0:
break
elif s >= c[i][0] and c[i][1] <= l:
s -= c[i][0]
if s < 0:
s += c[i][0]
else:
z.append(c[i][1])
if s != 0:
print(-1)
else:
print(len(z))
print(*z) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR LIST FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | s, l = map(int, input().split())
list1 = []
for i in range(1, l + 1):
list1.append((i & -i, i))
list1.sort(reverse=True)
ll = []
for i in range(l):
if list1[i][0] <= s:
ll.append(list1[i][1])
s -= list1[i][0]
if s == 0:
print(len(ll))
print(*ll)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | def main():
n, m = map(int, input().split())
step = 1 << m.bit_length() - 1
m += 1
l = [True] * m
while step:
if n >= step:
for i in range(step, m, step):
if l[i]:
if n >= step:
l[i] = False
n -= step
if not n:
l = [j for j, f in enumerate(l) if not f]
print(len(l))
print(" ".join(map(str, l)))
return
else:
break
step //= 2
print(-1)
main() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR IF VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR RETURN VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | h, m = list(map(int, input().split()))
k = []
while m > 0:
if h - m ^ m & m - 1 >= 0:
h -= m ^ m & m - 1
k.append(m)
m -= 1
if h > 0:
print(-1)
else:
print(len(k))
print(*k) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | s, l = map(int, input().split())
x = []
for i in range(1, l + 1):
x.append((i & -i, i))
ss = sum([x[i][0] for i in range(len(x))])
if ss < s:
print(-1)
else:
x = sorted(x, reverse=True)
xx = 0
res = []
rc = 0
for i in range(len(x)):
if xx + x[i][0] <= s:
xx += x[i][0]
res.append(x[i][1])
rc += 1
if xx == s:
print(rc)
for i in range(rc):
print(res[i], end=" ")
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR NUMBER |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | sum1, limit = map(int, input().split())
cou = 0
cnt = 0
visited = list()
num = list()
norm = list()
for i in range(1, limit + 1):
if i % 2 == 1:
num.append((i, 1))
else:
binary = bin(i).replace("0b", "")
index = 0
for j in range(len(binary)):
if binary[j] == "1":
index = j
binary = binary[index:]
num.append((i, int(binary, 2)))
num = sorted(num, key=lambda x: x[1], reverse=True)
for i in range(len(num)):
if num[i][1] + cou <= sum1:
cou += num[i][1]
visited.append(num[i][0])
cnt += 1
if cou == sum1:
print(cnt)
print(*visited)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | def per(x):
t = 0
y = str(bin(x))[2:]
for i in range(len(y) - 1, -1, -1):
if y[i] == "1":
t = i
break
return 2 ** (len(y) - t - 1), x
def perall(l):
for i in range(1, l + 1):
ans.append(per(i))
return ans
s, l = map(int, input().split())
ans = []
perall(l)
ans.sort(reverse=True)
answer = []
for i in ans:
if s - i[0] >= 0:
s -= i[0]
answer.append(i[1])
if s != 0:
print(-1)
else:
print(len(answer))
print(*answer) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING ASSIGN VAR VAR RETURN BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | table = [0] * 17
def maxsum(x):
b = bin(x)[2:]
ans = 0
for i, v in enumerate(reversed(b)):
if v == "1":
table[i] += 1
for n in range(i):
table[n] += 2 ** (i - n - 1)
for i, v in enumerate(table):
ans += 2**i * v
return ans
def lowbit(x):
b = bin(x)[2:]
for i, v in enumerate(reversed(b)):
if v == "1":
return 2**i
s, l = [int(x) for x in input().split()]
candi = []
mm = maxsum(l)
if s > mm:
print("-1")
else:
flag = True
while s:
for i in reversed(range(len(table))):
if table[i] > 0 and 2**i <= s:
s -= 2**i
table[i] -= 1
candi.append(table[i] * 2 ** (i + 1) + 2**i)
break
else:
flag = False
break
if flag:
print(len(candi))
for x in candi:
print(x, end=" ")
print()
else:
print("-1") | ASSIGN VAR BIN_OP LIST NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING RETURN BIN_OP NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | while True:
try:
def solution(s, l):
ans = list()
i = l
idn = t = 1
while i >= 1:
tr = i & t
if tr > 0 and t <= s:
s -= t
ans.append(i)
t, i = 1, i - 1
elif tr > 0 and t > s:
i -= 1
t = 1
else:
t *= 2
if s == 0:
break
if s == 0:
print(len(ans))
print(*ans)
else:
print(-1)
def read():
sum, limit = map(int, input().split())
solution(sum, limit)
if __name__ == "__main__":
read()
except EOFError:
break | WHILE NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR STRING EXPR FUNC_CALL VAR VAR |
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks.
Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation).
Can you help Picks and find any set S, that satisfies all the above conditions?
-----Input-----
The first line contains two integers: sum, limit (1 β€ sum, limit β€ 10^5).
-----Output-----
In the first line print an integer n (1 β€ n β€ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them.
If it's impossible to find a suitable set, print -1.
-----Examples-----
Input
5 5
Output
2
4 5
Input
4 3
Output
3
2 3 1
Input
5 1
Output
-1
-----Note-----
In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5.
In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 4. | s, l = map(int, input().split())
d = [-1] * (l + 1)
for i in range(1, l + 1):
if i % 2:
d[i] = 0
else:
d[i] = d[i // 2] + 1
p = sorted(list(range(1, l + 1)), key=lambda x: -d[x])
ans = []
for i in p:
if s == 0:
break
elif s < 1 << d[i]:
continue
else:
ans.append(i)
s -= 1 << d[i]
if s == 0:
print(len(ans))
print(*ans)
else:
print(-1) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER IF VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.readline
mod = 10**9 + 7
n, m = map(int, input().split())
Group = [i for i in range(m + 1)]
GroupOne = [0] * (m + 1)
Nodes = [1] * (m + 1)
def find(x):
while Group[x] != x:
x = Group[x]
return x
def Union(x, y):
if find(x) != find(y):
if Nodes[find(x)] < Nodes[find(y)]:
Nodes[find(y)] += Nodes[find(x)]
Nodes[find(x)] = 0
if GroupOne[find(x)] == 1 or GroupOne[find(y)] == 1:
GroupOne[find(x)] = 1
GroupOne[find(y)] = 1
Group[find(x)] = find(y)
else:
Nodes[find(x)] += Nodes[find(y)]
Nodes[find(y)] = 0
if GroupOne[find(x)] == 1 or GroupOne[find(y)] == 1:
GroupOne[find(x)] = 1
GroupOne[find(y)] = 1
Group[find(y)] = find(x)
ANS = []
for i in range(n):
V = tuple(map(int, input().split()))
if V[0] == 1:
x = V[1]
if GroupOne[find(x)] == 0:
ANS.append(i + 1)
GroupOne[find(x)] = 1
else:
continue
else:
x, y = V[1], V[2]
if find(x) == find(y) or GroupOne[find(x)] == 1 and GroupOne[find(y)] == 1:
continue
else:
Union(x, y)
ANS.append(i + 1)
print(pow(2, len(ANS), mod), len(ANS))
print(*ANS) | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF WHILE VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.buffer.readline
def _find(s, u):
p = []
while s[u] != u:
p.append(u)
u = s[u]
for v in p:
s[v] = u
return u
def _union(s, u, v):
su, sv = _find(s, u), _find(s, v)
if su != sv:
s[su] = sv
return su != sv
n, m = map(int, input().split())
s, solo = list(range(m + 1)), [0] * (m + 1)
res, pos = [], set()
for i in range(n):
p = list(map(int, input().split()))
if p[0] == 1:
pos.add(p[1])
p1 = _find(s, p[1])
if not solo[p1]:
res.append(i + 1)
solo[p1] = 1
else:
pos.add(p[1])
pos.add(p[2])
p1, p2 = _find(s, p[1]), _find(s, p[2])
if not (p1 == p2 or solo[p1] and solo[p2]):
_union(s, p1, p2)
res.append(i + 1)
if solo[p1] or solo[p2]:
solo[_find(s, p1)] = 1
cc = 0
for u in pos:
su = _find(s, u)
cc += 1
if not solo[su] and su == u:
cc -= 1
print(pow(2, cc, 10**9 + 7), len(res))
print(*res) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR RETURN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.readline
mod = 1000000007
n, m = map(int, input().split())
ans = []
groupi = [-1] * (m + 1)
groups = [2] * m
for i in range(m):
groups[i] = []
cur = 1
for i in range(n):
x = list(map(int, input().split()))
k = x.pop(0)
if k == 1:
x = x[0]
if groupi[x] == -1:
groupi[x] = 0
ans.append(i + 1)
if groupi[x] > 0:
ind = groupi[x]
for y in groups[ind]:
groupi[y] = 0
groupi[x] = 0
ans.append(i + 1)
if k == 2:
x1, x2 = x[0], x[1]
if groupi[x1] == -1:
if groupi[x2] == -1:
groupi[x1] = cur
groupi[x2] = cur
groups[cur] = [x1, x2]
cur += 1
ans.append(i + 1)
elif groupi[x2] == 0:
groupi[x1] = 0
ans.append(i + 1)
else:
groupi[x1] = groupi[x2]
groups[groupi[x2]].append(x1)
ans.append(i + 1)
elif groupi[x2] == -1:
if groupi[x1] == 0:
groupi[x2] = 0
ans.append(i + 1)
else:
groupi[x2] = groupi[x1]
groups[groupi[x1]].append(x2)
ans.append(i + 1)
elif groupi[x1] != groupi[x2]:
if groupi[x1] == 0 or groupi[x2] == 0:
if groupi[x1] == 0:
for y in groups[groupi[x2]]:
groupi[y] = 0
else:
for y in groups[groupi[x1]]:
groupi[y] = 0
else:
if len(groups[groupi[x1]]) < len(groups[groupi[x2]]):
x1, x2 = x2, x1
for y in groups[groupi[x2]]:
groupi[y] = groupi[x1]
groups[groupi[x1]].append(y)
ans.append(i + 1)
print(pow(2, len(ans), mod), len(ans))
print(*ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
class UnionFindVerSize:
def __init__(self, N):
self._parent = [n for n in range(0, N)]
self._size = [1] * N
self.source = [False] * N
self.group = N
def find_root(self, x):
if self._parent[x] == x:
return x
self._parent[x] = self.find_root(self._parent[x])
stack = [x]
while self._parent[stack[-1]] != stack[-1]:
stack.append(self._parent[stack[-1]])
for v in stack:
self._parent[v] = stack[-1]
return self._parent[x]
def unite(self, x, y):
gx = self.find_root(x)
gy = self.find_root(y)
if gx == gy:
return
self.group -= 1
if self._size[gx] < self._size[gy]:
self._parent[gx] = gy
self._size[gy] += self._size[gx]
self.source[gy] |= self.source[gx]
else:
self._parent[gy] = gx
self._size[gx] += self._size[gy]
self.source[gx] |= self.source[gy]
def add_size(self, x):
self.source[self.find_root(x)] = True
def get_size(self, x):
return self._size[self.find_root(x)]
def get_source(self, x):
return self.source[self.find_root(x)]
def is_same_group(self, x, y):
return self.find_root(x) == self.find_root(y)
input = sys.stdin.buffer.readline
m, n = map(int, input().split())
uf = UnionFindVerSize(n)
S = []
source = []
for i in range(m):
edge = tuple(map(int, input().split()))
if edge[0] == 1:
v = edge[1]
if not uf.get_source(v - 1):
uf.add_size(v - 1)
S.append(i + 1)
else:
u, v = edge[1], edge[2]
if not uf.is_same_group(u - 1, v - 1) and (
not uf.get_source(u - 1) or not uf.get_source(v - 1)
):
uf.unite(u - 1, v - 1)
S.append(i + 1)
ans = 1
k = 0
mod = 10**9 + 7
for i in range(n):
if uf.find_root(i) == i:
if uf.get_source(i):
k += uf.get_size(i)
else:
k += uf.get_size(i) - 1
print(pow(2, k, mod), len(S))
S.sort()
print(*S) | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST VAR WHILE VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL 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 ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.buffer.readline
class UnionFind:
def __init__(self, n):
self.parent = [-1] * n
self.n = n
self.cnt = n
def root(self, x):
if self.parent[x] < 0:
return x
else:
self.parent[x] = self.root(self.parent[x])
return self.parent[x]
def merge(self, x, y):
x = self.root(x)
y = self.root(y)
if x == y:
return False
if self.parent[x] > self.parent[y]:
x, y = y, x
self.parent[x] += self.parent[y]
self.parent[y] = x
self.cnt -= 1
return True
def is_same(self, x, y):
return self.root(x) == self.root(y)
def size(self, x):
return -self.parent[self.root(x)]
def count(self):
return self.cnt
def groups(self):
res = [[] for _ in range(self.n)]
for i in range(self.n):
res[self.root(i)].append(i)
return [group for group in res if group]
n, m = map(int, input().split())
info = [list(map(int, input().split())) for i in range(n)]
MOD = 10**9 + 7
uf = UnionFind(m)
start = []
res = []
for i, (k, *vs) in enumerate(info):
if len(vs) == 2:
u, v = vs
u -= 1
v -= 1
if not uf.is_same(u, v):
uf.merge(u, v)
res.append(i + 1)
else:
u = vs[0] - 1
if start:
if not uf.is_same(start[-1], u):
uf.merge(start[-1], u)
res.append(i + 1)
start.append(u)
else:
res.append(i + 1)
start.append(u)
print(pow(2, len(res), MOD), len(res))
print(*res) | IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER RETURN NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR 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 VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF VAR IF FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.readline
MOD = 10**9 + 7
class UnionFind:
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
dic = {r: [] for r in self.roots()}
for i in range(self.n):
dic[self.find(i)].append(i)
return dic
def __str__(self):
return "\n".join("{}: {}".format(r, self.members(r)) for r in self.roots())
def main():
n, m = map(int, input().split())
ans = []
UF = UnionFind(m + 1)
for i in range(1, n + 1):
q = list(map(int, input().split()))
if q[0] == 1:
x = 0
y = q[1]
else:
x = q[1]
y = q[2]
if not UF.same(x, y):
ans.append(i)
UF.union(x, y)
cnt = 0
for x in UF.roots():
cnt += UF.size(x) - 1
t = pow(2, cnt, MOD)
print(t, len(ans))
print(*ans)
for _ in range(1):
main() | IMPORT ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR RETURN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_DEF RETURN VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR LIST VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL STRING FUNC_CALL STRING VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | from sys import stdin, stdout
n, m = [int(i) for i in stdin.readline().split()]
l = []
d1 = {}
a = []
p = [i for i in range(m)]
r = [(0) for i in range(m)]
mod = 10**9 + 7
def find(x):
while p[x] != x:
x = p[x]
return x
def power(x):
f = 1
ct = 2
while x:
if x % 2 == 1:
f = f * ct
f %= mod
ct = ct * ct
ct %= mod
x //= 2
return f
for i in range(n):
x = [(int(j) - 1) for j in stdin.readline().split()][1:]
if len(x) == 1:
x[0] = find(x[0])
if d1.get(x[0], 0) == 0:
l.append(i)
d1[x[0]] = 1
else:
u, v = find(x[0]), find(x[1])
if d1.get(u, 0) == 1 and d1.get(v, 0) == 1:
continue
elif u == v:
continue
elif d1.get(u, 0) == 1:
d1[v] = 1
l.append(i)
elif d1.get(v, 0) == 1:
d1[u] = 1
l.append(i)
else:
px = u
py = v
if r[px] > r[py]:
p[py] = px
elif r[px] < r[py]:
p[px] = py
else:
p[py] = px
r[px] += 1
l.append(i)
stdout.write(str(power(len(l))) + " " + str(len(l)) + "\n")
for i in l:
stdout.write(str(i + 1) + " ") | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF WHILE VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING FUNC_CALL VAR FUNC_CALL VAR VAR STRING FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
def input():
return sys.stdin.buffer.readline()[:-1]
class UnionFind:
def __init__(self, size):
self.table = [(-1) for _ in range(size)]
def find(self, x):
while self.table[x] >= 0:
if self.table[self.table[x]] >= 0:
self.table[x] = self.table[self.table[x]]
x = self.table[x]
return x
def same(self, x, y):
return self.find(x) == self.find(y)
def unite(self, x, y):
s1 = self.find(x)
s2 = self.find(y)
if s1 != s2:
r1 = self.table[s1]
r2 = self.table[s2]
if r1 <= r2:
self.table[s2] = s1
if r1 == r2:
self.table[s1] -= 1
else:
self.table[s1] = s2
return
m, n = map(int, input().split())
uf = UnionFind(n + 1)
ans = []
for i in range(1, m + 1):
q = list(map(int, input().split()))
if q[0] == 1:
if uf.same(q[1] - 1, n):
continue
else:
ans.append(i)
uf.unite(q[1] - 1, n)
elif uf.same(q[1] - 1, q[2] - 1):
continue
else:
ans.append(i)
uf.unite(q[1] - 1, q[2] - 1)
print(pow(2, len(ans), 10**9 + 7), len(ans))
print(*ans) | IMPORT FUNC_DEF RETURN FUNC_CALL VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR RETURN ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.buffer.readline
def prog():
n, m = map(int, input().split())
mod = 10**9 + 7
has_one = [0] * (m + 1)
basis = []
sizes = [1] * (m + 1)
parent = list(range(m + 1))
def find_parent(v):
if v == parent[v]:
return v
v = find_parent(parent[v])
return v
def union_sets(a, b):
a = find_parent(a)
b = find_parent(b)
if a != b and (not has_one[a] or not has_one[b]):
if sizes[a] < sizes[b]:
a, b = b, a
parent[b] = a
sizes[a] += sizes[b]
has_one[a] = has_one[a] | has_one[b]
return True
else:
return False
for i in range(1, n + 1):
a = list(map(int, input().split()))
if a[0] == 1:
par = find_parent(a[1])
if not has_one[par]:
has_one[par] = 1
basis.append(i)
elif union_sets(a[1], a[2]):
basis.append(i)
print(pow(2, len(basis), mod), len(basis))
print(*basis)
prog() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.readline
N, M = map(int, input().split())
mod = 10**9 + 7
base = [0] * (M + 1)
e = [[] for _ in range(M + 1)]
res = []
class UnionFind:
def __init__(self, n):
self.n = n
self.root = [-1] * (n + 1)
self.rnk = [0] * (n + 1)
def Find_Root(self, x):
if self.root[x] < 0:
return x
else:
self.root[x] = self.Find_Root(self.root[x])
return self.root[x]
def Unite(self, x, y):
x = self.Find_Root(x)
y = self.Find_Root(y)
if x == y:
return
elif self.rnk[x] > self.rnk[y]:
self.root[x] += self.root[y]
self.root[y] = x
else:
self.root[y] += self.root[x]
self.root[x] = y
if self.rnk[x] == self.rnk[y]:
self.rnk[y] += 1
def isSameGroup(self, x, y):
return self.Find_Root(x) == self.Find_Root(y)
def Count(self, x):
return -self.root[self.Find_Root(x)]
uf = UnionFind(M)
for i in range(1, N + 1):
a = list(map(int, input().split()))
if a[0] == 1:
a.append(0)
u, v = a[1:]
if uf.isSameGroup(u, v):
continue
else:
uf.Unite(u, v)
res.append(i)
print(pow(2, len(res), mod), len(res))
print(*res) | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN IF VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = iter(sys.stdin.read().splitlines()).__next__
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, x):
found = x
while self.parent[found] != found:
found = self.parent[found]
while x != found:
y = self.parent[x]
self.parent[x] = found
x = y
return found
def union(self, x, y):
self.parent[self.find(x)] = self.find(y)
n, m = map(int, input().split())
S_prime = []
uf = UnionFind(m + 1)
for index in range(1, n + 1):
vector_description = [(int(i) - 1) for i in input().split()] + [m]
u, v = vector_description[1:3]
if uf.find(u) == uf.find(v):
continue
S_prime.append(index)
uf.union(u, v)
T_size = pow(2, len(S_prime), 10**9 + 7)
print(T_size, len(S_prime))
print(*sorted(S_prime)) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR LIST VAR ASSIGN VAR VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def union(self, a, b):
self.parent[self.find(b)] = self.find(a)
input = sys.stdin.readline
n, m = map(int, input().split())
UF = UnionFind(m + 1)
MOD = 10**9 + 7
out = []
for i in range(1, n + 1):
l = list(map(int, input().split()))
if len(l) == 2:
u = 0
v = l[1]
else:
_, u, v = l
uu = UF.find(u)
vv = UF.find(v)
if uu != vv:
UF.union(uu, vv)
out.append(i)
print(pow(2, len(out), MOD), len(out))
print(" ".join(map(str, out))) | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.buffer.readline
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def union(self, a, b):
self.parent[self.find(b)] = self.find(a)
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
n, m = [int(x) for x in input().split()]
uf = UnionFind(m + 1)
hasOne = [(False) for _ in range(m + 1)]
sPrime = []
for i in range(n):
inp = [int(x) for x in input().split()]
if inp[0] == 1:
parent = uf.find(inp[1])
if hasOne[parent] == False:
sPrime.append(i + 1)
hasOne[parent] = True
else:
parent1, parent2 = uf.find(inp[1]), uf.find(inp[2])
if parent1 != parent2:
if not (hasOne[parent1] and hasOne[parent2]):
sPrime.append(i + 1)
uf.union(inp[1], inp[2])
newParent = uf.find(inp[1])
hasOne[newParent] = hasOne[parent1] or hasOne[parent2]
S_magnitude = len(sPrime)
T_magnitude = pow(2, S_magnitude, 10**9 + 7)
print("{} {}".format(T_magnitude, S_magnitude))
oneLineArrayPrint(sPrime) | IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
readline = sys.stdin.readline
class UF:
def __init__(self, num):
self.par = [-1] * num
self.color = [0] * num
def find(self, x):
if self.par[x] < 0:
return x
else:
stack = []
while self.par[x] >= 0:
stack.append(x)
x = self.par[x]
for xi in stack:
self.par[xi] = x
return x
def col(self, x):
return self.color[self.find(x)]
def paint(self, x):
self.color[self.find(x)] = 1
def union(self, x, y):
rx = self.find(x)
ry = self.find(y)
if rx != ry:
if self.par[rx] > self.par[ry]:
rx, ry = ry, rx
self.par[rx] += self.par[ry]
self.par[ry] = rx
self.color[rx] |= self.color[ry]
return True
return False
N, M = map(int, readline().split())
MOD = 10**9 + 7
ans = []
T = UF(M)
for m in range(N):
k, *x = map(int, readline().split())
if k == 1:
u = x[0] - 1
if not T.col(u):
ans.append(m + 1)
T.paint(u)
else:
u, v = x[0] - 1, x[1] - 1
if T.col(u) and T.col(v):
continue
if T.union(u, v):
ans.append(m + 1)
print(pow(2, len(ans), MOD), len(ans))
print(" ".join(map(str, ans))) | IMPORT ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FUNC_DEF IF VAR VAR NUMBER RETURN VAR ASSIGN VAR LIST WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF RETURN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
MOD = 10**9 + 7
input = sys.stdin.buffer.readline
class UnionFind:
def __init__(self, n):
self.parent = list(range(n))
def find(self, a):
acopy = a
while a != self.parent[a]:
a = self.parent[a]
while acopy != a:
self.parent[acopy], acopy = a, self.parent[acopy]
return a
def union(self, a, b):
self.parent[self.find(b)] = self.find(a)
def oneLineArrayPrint(arr):
print(" ".join([str(x + 1) for x in arr]))
def solveActual():
uf = UnionFind(m + 2)
for i, x in enumerate(vS):
if len(x) == 1:
x.append(m + 1)
x.append(i)
vS.sort(key=lambda x: x[2])
sPrime = []
for p1, p2, index in vS:
if uf.find(p1) != uf.find(p2):
uf.union(p1, p2)
sPrime.append(index)
TSize = pow(2, len(sPrime), MOD)
print("{} {}".format(TSize, len(sPrime)))
oneLineArrayPrint(sPrime)
n, m = [int(x) for x in input().split()]
vS = []
for _ in range(n):
xx = [int(x) for x in input().split()]
for i in range(1, len(xx)):
xx[i] -= 1
vS.append(xx[1:])
solveActual() | IMPORT ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | import sys
input = sys.stdin.buffer.readline
def _find(s, u):
p = []
while s[u] != u:
p.append(u)
u = s[u]
for v in p:
s[v] = u
return u
def _union(s, u, v):
su, sv = _find(s, u), _find(s, v)
if su != sv:
s[su] = sv
n, m = map(int, input().split())
s, res = list(range(m + 1)), []
for i in range(n):
p = list(map(int, input().split()))
if p[0] == 1:
u, v = 0, p[1]
else:
u, v = p[1], p[2]
su, sv = _find(s, u), _find(s, v)
if su != sv:
_union(s, su, sv)
res.append(i + 1)
print(pow(2, len(res), 10**9 + 7), len(res))
print(*res) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST WHILE VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for _ in range(t):
n, m = list(map(int, input().split()))
if m < n:
print(0)
else:
m += 1
n_b = list(bin(n)[2:])
m_b = list(bin(m)[2:])
n_b = ["0"] * (30 - len(n_b)) + n_b
m_b = ["0"] * (30 - len(m_b)) + m_b
msb = -1
for i in range(0, len(n_b)):
if n_b[i] == "1" and m_b[i] != "1":
msb = i
break
if msb == -1:
print(int("".join(m_b), 2) ^ int("".join(n_b), 2))
else:
for i in range(msb, len(n_b)):
if n_b[i] == "1":
m_b[i] = "1"
else:
m_b[i] = "0"
print(int("".join(m_b), 2) ^ int("".join(n_b), 2)) | 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def solve(n, m):
ans = 0
for i in range(31, -1, -1):
nn = n | (1 << i) - 1
nn ^= ans
if nn <= m:
ans += 1 << i
return ans
for i in range(int(input())):
a, b = map(int, input().split())
print(solve(a, b)) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER VAR VAR IF VAR VAR VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | n_testcase = int(input())
for testcase in range(n_testcase):
n, m = (int(x) for x in input().split())
m += 1
n2 = 1
while n2 <= n:
n2 <<= 1
answer = m // n2 * n2
m %= n2
n2 >>= 1
while n2 >= 1:
if n & n2 == n2:
m = max(m - n2, 0)
elif m >= n2:
answer += n2
m -= n2
n2 >>= 1
print(answer) | 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 VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
if n > m:
ans = 0
else:
l = max(len(bin(n)), len(bin(m))) - 1
n0 = list("0" * (l - len(bin(n)) + 2) + bin(n)[2:])
m0 = list("0" * (l - len(bin(m)) + 2) + bin(m)[2:])
x = [0] * l
f = 0
for i in range(l):
if n0[i] == "0" and m0[i] == "1":
x[i] = 1
elif n0[i] == "1" and m0[i] == "0":
f = 1
break
ans = 0
p = 1
if not f:
for i in range(l - 1, -1, -1):
if n0[i] == m0[i] == "0":
x[i] = 1
break
x[i] = 0
for i in range(l - 1, -1, -1):
ans += x[i] * p
p *= 2
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | from sys import stdin
input = stdin.readline
for _ in range(int(input())):
n, m = map(int, input().split())
x = bin(n)[2:].zfill(32)
y = bin(m)[2:].zfill(32)
ans = []
mini = ["1"] * 32
for i in range(32):
if y[i] == "1":
if x[i] == "1":
ans.append("0")
else:
ans.append("1")
elif x[i] == "1":
mini = min(mini, ans + ["0"] * (32 - len(ans)))
ans.append("1")
else:
mini = min(mini, ans + ["1"] + ["0"] * (31 - len(ans)))
ans.append("0")
print(int("".join(mini), 2)) | ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING IF VAR VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP LIST STRING BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR LIST STRING BIN_OP LIST STRING BIN_OP NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
def fun(n, m):
nbin = bin(n)[2:]
mbin = bin(m + 1)[2:]
k = ""
if len(nbin) > len(mbin):
return 0
elif len(mbin) > len(nbin):
idx = len(mbin) - len(nbin)
k = mbin[:idx]
nbin = "".join(["0"] * (len(mbin) - len(nbin))) + nbin
else:
idx = 0
while idx < len(nbin):
if nbin[idx] == mbin[idx]:
k += "0"
elif nbin[idx] == "0" and mbin[idx] == "1":
k += "1"
else:
k = k + "".join(["0"] * (len(nbin) - idx))
break
idx += 1
return int(k, 2)
t = int(input())
for i in range(t):
n, m = map(int, input().split())
print(fun(n, m)) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL STRING BIN_OP LIST STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING ASSIGN VAR BIN_OP VAR FUNC_CALL STRING BIN_OP LIST STRING BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for i in range(int(input())):
n, m = map(int, input().split())
mex = 0
m += 1
z = 1 << 30
while z and n < m:
if not z & n and z & m:
mex += z
n += z
z >>= 1
print(mex) | 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 VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n, m = map(int, input().split())
if m < n:
print(0)
continue
x = 0
for i in range(32, -1, -1):
if n & 1 << i == 0:
if m & 1 << i != 0:
x |= 1 << i
elif m & 1 << i == 0:
break
if x ^ n <= m:
for i in range(32):
if n ^ (x | 1 << i) > m:
x |= 1 << i
for j in range(i - 1, -1, -1):
if x & 1 << j != 0:
x ^= 1 << j
break
print(x) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def solve(n, m):
if n > m:
print(0)
return
d = (1 << 35) - 1
i = 40
while i > -1:
dd = d - (1 << i)
if dd > m and dd & n == n:
d = dd
i -= 1
print(n ^ d)
t = int(input())
for i in range(t):
n, m = [int(j) for j in input().split()]
solve(n, m) | FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP 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 VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for hh in range(0, t):
n, m = [int(x) for x in input().split()]
if n == 0:
print(m + 1)
elif m < n:
print(0)
else:
li = [0] * 34
idx = 33
norig = n
while n > 0:
if n % 2 == 1:
li[idx] = 1
n = n // 2
idx -= 1
li1 = []
po = 1
for i in range(33, -1, -1):
if li[i] == 0:
li1.append(po)
po = po * 2
n = m + 1 - norig
ans = 0
while n > 0:
su = 0
for i in range(0, len(li1)):
su += li1[i]
if su >= n:
n = n - li1[i]
ans += li1[i]
break
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.buffer.readline
def solve_tc():
n, m = map(int, input().split())
m += 1
ans = 0
for k in range(30, -1, -1):
if n >= m:
break
l = m >> k & 1
if l and l != n >> k & 1:
ans |= 1 << k
n |= 1 << k
return ans
t = int(input())
for _ in range(t):
sys.stdout.write(str(solve_tc()) + "\n") | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR STRING |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def LI():
return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def LI1():
return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number):
return [LI1() for _ in range(rows_number)]
def SI():
return sys.stdin.readline().rstrip()
inf = 10**16
md = 10**9 + 7
def solve():
n, m = LI()
if n > m:
print(0)
return
ans = n ^ m
cur = ans & n
if cur:
i = cur.bit_length()
ans = ans >> i << i
else:
for i in range(32):
if ans >> i & 1 == 0 and n >> i & 1 == 0:
ans = ans >> i << i
ans |= 1 << i
break
print(ans)
for testcase in range(II()):
solve() | IMPORT ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING 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 RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.buffer.readline
def solve():
k = M + 1
ans = 0
for i in range(30, -1, -1):
if N >> i & 1 > k >> i & 1:
break
ans |= N & 1 << i ^ k & 1 << i
return ans
test_cases = int(input())
for test_case in range(test_cases):
N, M = map(int, input().split())
print(solve()) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP 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 EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def solve(n, m):
if m < n:
return 0
M = bin(m)[2:]
N = bin(n)[2:]
N = "0" * (len(M) - len(N)) + N
ans = []
nstart = -1
lastmzero = -1
for i, (mc, nc) in enumerate(zip(M, N)):
if nc == "1" and nstart < 0:
nstart = i
if nstart < 0:
ans.append(mc)
elif mc == "1" and nc == "1":
ans.append("0")
elif mc == "1" and nc == "0":
ans.append("1")
elif mc == "0" and nc == "0":
ans.append("0")
else:
return int("".join(ans) + "0" * (len(M) - i), base=2)
if mc == "0":
lastmzero = i
if lastmzero >= 0:
return int(
"".join(ans[:lastmzero]) + "1" + "0" * (len(M) - 1 - lastmzero), base=2
)
return m + 1
T = int(input())
for _ in range(T):
n, m = map(int, input().split())
print(solve(n, m)) | FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING IF VAR STRING VAR STRING EXPR FUNC_CALL VAR STRING RETURN FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR STRING ASSIGN VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL STRING VAR VAR STRING BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for _ in range(t):
n, m = map(int, input().split())
if m < n:
print(0)
continue
ans = 0
for pos in range(30, -1, -1):
bitn = n & 1 << pos > 0
bitm = m + 1 & 1 << pos > 0
if bitn == bitm:
continue
elif bitn == 1 and bitm == 0:
break
elif bitn == 0 and bitm == 1:
ans += 1 << pos
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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER IF VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
n, m = [int(c) for c in input().split()]
m += 1
ans = 0
for i in range(30, -1, -1):
if n >> i & 1 == m >> i & 1:
continue
if n >> i & 1 == 1:
break
if n >> i & 1 == 0:
ans = ans | 1 << i
print(ans) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for _ in range(int(input())):
n, k = map(int, input().split())
c = bin(n)[2:]
d = "0" + bin(k)[2:]
c = "0" * (len(d) - len(c)) + c
ans = 0
for i in range(len(d)):
if d[i] == "1" and c[i] == "0":
ans += 1 << len(d) - i - 1
elif "1" * (len(d) - i - 1) == d[i + 1 :] and c[i] == "0":
ans += 1 << len(d) - i - 1
break
elif d[i] == "0" and c[i] == "1":
break
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP STRING FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | T = int(input())
for tc in range(T):
n, m = map(int, input().split())
p = m + 1
sn = bin(n)[2:]
sp = bin(p)[2:]
sn = "0" * max(0, len(sp) - len(sn)) + sn
sp = "0" * max(0, len(sn) - len(sp)) + sp
res = []
for i in range(len(sn)):
if sn[i] == sp[i]:
res.append("0")
elif sn[i] == "0" and sp[i] == "1":
res.append("1")
elif sn[i] == "1" and sp[i] == "0":
break
zero_pad = "0" * (len(sn) - len(res))
res.append(zero_pad)
res = "".join(res)
print(int(res, 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 BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
def mapInt():
return map(int, input().split())
def code_init():
sys.stdin = open("input.txt", "r")
sys.stdout = open("output.txt", "w")
def solve(n, m):
m += 1
ans = 0
for i in range(30, -1, -1):
if n >= m:
break
if n >> i & 1 == m >> i & 1:
continue
if m >> i & 1:
ans |= 1 << i
n |= 1 << i
return ans
def main():
t = int(input())
for _ in range(t):
n, m = mapInt()
res = solve(n, m)
print(res)
main() | IMPORT FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for _ in range(int(input())):
n, m = map(int, input().split(" "))
p = m + 1
p = bin(p)[2:]
z = bin(n)[2:]
if len(z) >= len(p):
p = p.zfill(len(z))
else:
z = z.zfill(len(p))
k = ""
for x in range(len(z)):
if z[x] == "0" and p[x] == "0":
k += "0"
elif z[x] == "0" and p[x] == "1":
k += "1"
elif z[x] == "1" and p[x] == "0":
for y in range(x, len(z)):
k += "0"
break
else:
k += "0"
print(int(k, 2)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
def solve():
n, m = map(int, input().split())
ans = 0
flag = 0
for i in range(30, -1, -1):
x, y = n >> i & 1, m >> i & 1
if flag == 0:
if x == 1 and y == 0:
flag = 1
elif x == 0 and y == 1:
ans |= 1 << i
i = 0
while flag == 0:
if ans >> i & 1 == 0 and n ^ (ans | 1 << i) > m:
ans |= 1 << i
if i:
ans = ans >> i << i
flag = 1
i += 1
return ans
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for i in range(t):
print(solve()) | IMPORT FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR IF VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | T = int(input())
for t in range(T):
n, m = map(int, input().split())
if m < n:
print(0)
continue
N = bin(n)[2:]
P = bin(m + 1)[2:]
k = ["0"] * max(len(N), len(P))
N = "0" * (len(P) - len(N)) + N
for i in range(len(P)):
if N[i] == "1" and P[i] == "0":
break
if P[i] == N[i]:
k[i] = "0"
else:
k[i] = "1"
print(int("".join(k), 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for i in range(int(input())):
n, m = list(map(int, input().split()))
a = bin(n)[2:]
b = bin(m)[2:]
a = "0" * (32 - len(a)) + a
b = "0" * (32 - len(b)) + b
c = ""
for i in range(32):
if a[i] == "1" and b[i] == "0":
c += "0" * (32 - i)
print(int(c, base=2))
break
if a[i] == b[i]:
c += "0"
else:
c += "1"
else:
z = 2**32
c = ""
for i in range(32):
if a[i] == "0" and b[i] == "0":
z = min(z, int(c + "1" + "0" * (31 - i), base=2))
if a[i] == b[i]:
c += "0"
else:
c += "1"
print(z) | 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 VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR BIN_OP STRING BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR VAR STRING VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR STRING BIN_OP STRING BIN_OP NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR STRING VAR STRING EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | tcase = int(input().strip())
for _ in range(tcase):
n, m = map(int, input().strip().split())
if n > m:
print(0)
else:
ans = 0
m += 1
for pos in range(30, -1, -1):
if n >> pos & 1 == m >> pos & 1:
continue
elif n >> pos & 1:
break
else:
ans |= 1 << pos
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL 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 VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
n, m = map(int, input().split())
m += 1
ans = 0
b = 0
while 1 << b + 1 <= max(n, m):
b += 1
for i in range(b, -1, -1):
if n >> i & 1 and m >> i & 1 ^ 1:
break
elif n >> i & 1 ^ 1 and m >> i & 1:
ans |= 1 << i
print(ans) | 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 VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def msb(x):
i = 0
p = 1
assert x != 0
while p < x:
i += 1
p = p << 1
return i
def solve():
n, m = map(int, input().split(" "))
M = m + 1
mex = 0
for bit in range(29, -1, -1):
l_bit = n >> bit & 1 > 0
r_bit = M >> bit & 1 > 0
set_this_bit = False
if r_bit and not l_bit:
set_this_bit = True
elif l_bit and not r_bit:
return mex
if set_this_bit:
mex = mex | 1 << bit
return mex
def main():
t = int(input())
for tt in range(t):
print(solve())
main() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR RETURN VAR IF VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for _ in range(t):
n, m = map(int, input().split())
a = bin(m + 1)[2:]
b = bin(n)[2:]
a1 = ["0"] * 30
a2 = ["0"] * 30
j = 29
for i in range(len(a) - 1, -1, -1):
a1[j] = a[i]
j -= 1
j = 29
for i in range(len(b) - 1, -1, -1):
a2[j] = b[i]
j -= 1
a3 = ["0"] * 30
for i in range(30):
if a1[i] == a2[i]:
a3[i] = "0"
elif a2[i] == "1" and a1[i] == "0":
break
else:
a3[i] = "1"
ans = int("".join(a3), 2)
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 BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.buffer.readline
def f(n, m, i):
if i < 0:
return 0
if i == 0:
if m & 1:
return 2
elif n & 1:
return 0
else:
return 1
if n >> i & 1:
if m >> i & 1:
x = f(n, m, i - 1)
if x == 1 << i:
return 1 << i + 1
else:
return x
else:
return 0
elif m >> i & 1:
x = f(n, m, i - 1)
return (1 << i) + x
else:
return f(n, m, i - 1)
for t in range(int(input())):
N, M = map(int, input().split())
print(f(N, M, 31)) | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP NUMBER VAR RETURN BIN_OP NUMBER BIN_OP VAR NUMBER RETURN VAR RETURN NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER 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 NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
def solve():
n, m = map(int, input().split())
m += 1
ans = p = 0
while m or n:
i, j = m & 1, n & 1
if i == 1 and j == 0:
ans += 2**p
elif i == 0 and j == 1:
ans = 0
p += 1
m >>= 1
n >>= 1
return ans
for _ in range(int(input())):
print(solve()) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
def solve():
n, m = map(int, input().split())
if n > m:
print(0)
return
for i in range(31):
c = 1 << i
if c > n and c > m:
r = 0
for j in range(i, -1, -1):
if n ^ r > m:
print(r)
break
if n ^ r | (1 << j + 1) - 1 <= m:
r ^= 1 << j + 1
print(r)
return
if m & 1 << j != 0:
if n & 1 << j == 0:
r |= 1 << j
if n ^ r > m:
print(r)
return
if n ^ r <= m:
r ^= 1
print(r)
return
print(r)
break
for i in range(int(input())):
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def ind(ch):
return ord(ch) - ord("a")
def db(n):
k = list(bin(n).replace("0b", ""))
f = len(k)
rem = 31 - f
k = ["0"] * rem + k
return k
def bd(arr):
p = 1
s = 0
for i in range(len(arr) - 1, -1, -1):
s += p * int(arr[i])
p *= 2
return s
def main():
t = int(input())
for _ in range(t):
arr = list(map(int, input().split()))
n = arr[0]
m = arr[1]
if n > m:
print(0)
continue
bm = db(m)
bn = db(n)
ans = ["0"] * 31
f = 30
for i in range(31):
if bm[i] == "1":
f = i
break
g = -1
xor = [0] * 31
trig = False
for i in range(31):
if bm[i] == "1" and bn[i] == "0":
ans[i] = "1"
if bm[i] == "0" and bn[i] == "0":
g = i
xor[i] = int(bn[i]) ^ int(ans[i])
if xor[i] > int(bm[i]):
trig = True
break
if trig:
c = bd(ans)
print(c)
continue
ans[g] = "1"
for i in range(g + 1, 31):
ans[i] = "0"
print(bd(ans))
main() | FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP LIST STRING VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for _ in range(int(input())):
n, m = map(int, input().split())
a, b = m & ~n, ~m & n
c = a
if b:
z = 1
while z <= b:
c &= ~z
z <<= 1
else:
x = m + 1 & ~m
c = (c | x) & ~(x - 1)
print(c) | 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 BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def f(n, m):
ans = 0
m += 1
for i in range(30, -1, -1):
if n >= m:
break
if n & 1 << i == m & 1 << i:
continue
if m & 1 << i:
ans += 1 << i
n += 1 << i
return ans
for _ in range(int(input())):
a, b = map(int, input().strip().split())
print(f(a, b)) | FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for tt in range(t):
n, m = map(int, input().split())
m += 1
z = 0
for i in range(31)[::-1]:
if n >> i & 1:
m -= 1 << i
elif m >= 1 << i:
m -= 1 << i
z += 1 << i
print(z) | 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 VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR IF VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | from sys import stdin, stdout
input = stdin.readline
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
ans = 0
flg = 0
for i in range(34, -1, -1):
if n & 1 << i and not m & 1 << i:
flg = 1
elif not n & 1 << i and not m & 1 << i:
continue
elif n & 1 << i and m & 1 << i:
continue
elif not flg:
ans += 1 << i
if not flg:
for i in range(35):
if not n & 1 << i and not m & 1 << i:
ans += 1 << i
for j in range(i):
if not n & 1 << j and m & 1 << j:
ans -= 1 << j
break
print(ans) | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF VAR VAR BIN_OP NUMBER VAR IF VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
R = lambda: map(int, input().split())
I = lambda: int(input())
S = lambda: input().rstrip("\n")
L = lambda: list(R())
def check(n, i):
return n >> i & 1
def solve():
n, m = R()
if m < n:
print(0)
return
ans = 0
m += 1
for i in range(30, -1, -1):
if True == check(n, i) and False == check(m, i):
break
elif False == check(n, i) and True == check(m, i):
ans |= 1 << i
print(ans)
return
for _ in range(I()):
solve() | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR IF NUMBER FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
LI = lambda: list(map(int, sys.stdin.readline().split()))
MI = lambda: map(int, sys.stdin.readline().split())
SI = lambda: sys.stdin.readline().strip("\n")
II = lambda: int(sys.stdin.readline())
for _ in range(II()):
n, m = MI()
n, p = bin(n)[2:], bin(m + 1)[2:]
l = max(len(n), len(p))
n, p = "0" * (l - len(n)) + n, "0" * (l - len(p)) + p
s = ""
for i in range(l):
if n[i] == "1":
if p[i] == "1":
s += "0"
else:
s += (l - len(s)) * "0"
break
elif p[i] == "1":
s += "1"
else:
s += "0"
print(int(s, 2)) | IMPORT 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 FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING IF VAR VAR STRING VAR STRING VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING IF VAR VAR STRING VAR STRING VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def ans(n, m):
a = bin(n)[2:]
b = bin(m + 1)[2:]
x = len(a)
y = len(b)
a = "0" * (max(x, y) - len(a)) + a
b = "0" * (max(x, y) - len(b)) + b
an = ""
f = 0
for i in range(max(x, y)):
if f == 1:
an = an + "0"
elif a[i] == "0":
if b[i] == "0":
an = an + "0"
else:
an = an + "1"
elif b[i] == "0":
f = 1
an = an + "0"
else:
an = an + "0"
answer = int(an, 2)
return answer
for _ in range(int(input())):
n, m = map(int, input().split())
print(ans(n, m)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR STRING IF VAR VAR STRING IF VAR VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING IF VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR FUNC_CALL 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 two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n, m = map(int, input().split())
answer = 0
if n > m:
print(0)
else:
nbin = bin(n)[2:]
mbin = bin(m)[2:]
nlen = len(nbin)
mlen = len(mbin)
nbin = "0" * (mlen - nlen) + nbin
data = ["0"] * mlen
flg = False
for i in range(mlen):
if nbin[i] == "0" and mbin[i] == "1":
data[i] = "1"
elif nbin[i] == "1" and mbin[i] == "0":
data[i] = "0"
flg = True
break
if not flg:
flg2 = -1
for i in range(mlen - 1, -1, -1):
if nbin[i] == "0" and mbin[i] == "0":
data[i] = "1"
flg2 = i
break
if flg2 >= 0:
for i in range(flg2 + 1, mlen):
data[i] = "0"
else:
data = ["1"] + ["0"] * mlen
answer = int("".join(data), 2)
print(answer)
else:
answer = int("".join(data), 2)
print(answer) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING ASSIGN VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR STRING ASSIGN VAR BIN_OP LIST STRING BIN_OP LIST STRING VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def main():
t = int(input())
for _ in range(t):
n, m = [int(word) for word in input().split()]
if n > m:
print(0)
else:
i = 0
while 1 << i <= m:
i += 1
ans = 1 << i
x = 0
while i >= 0:
y = x ^ 1 << i
if n ^ y > m:
ans = min(ans, y)
elif n ^ x <= n ^ y:
x = y
else:
pass
i -= 1
print(ans)
main() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
m += 1
ans = 0
for i in range(31)[::-1]:
if n >= m:
break
if n >> i & 1 == m >> i & 1:
continue
if m >> i & 1:
ans |= 1 << i
n |= 1 << i
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | from sys import gettrace, stdin
if gettrace():
def inputi():
return input()
else:
def input():
return next(stdin)[:-1]
def inputi():
return stdin.buffer.readline()
def msb(i):
i |= i >> 1
i |= i >> 2
i |= i >> 4
i |= i >> 8
i |= i >> 16
i += 1
return i >> 1
def solve(n: int, m: int):
m1 = m + 1
bl = max(m1.bit_length(), n.bit_length())
res = 0
for i in range(bl - 1, -1, -1):
bit = 1 << i
if bit & n == 0 and bit & m1 != 0:
res += bit
elif bit & n != 0 and bit & m1 == 0:
break
return res
def main():
t = int(input())
for _ in range(t):
n, m = map(int, input().split())
print(solve(n, m))
main() | IF FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for xx in range(t):
[n, m] = [int(x) for x in input().split()]
i = 0
ans = 0
m += 1
bitn = []
bitm = []
while n > 0 or m > 0:
bitn.append(n % 2)
bitm.append(m % 2)
n = n // 2
m = m // 2
bitm.reverse()
bitn.reverse()
control = 0
ans = 0
for i in range(len(bitn)):
if control == 1:
ans *= 2
elif bitn[i] == 1 and bitm[i] == 1:
ans *= 2
elif bitn[i] == 0 and bitm[i] == 1:
ans = 2 * ans + 1
elif bitn[i] == 1 and bitm[i] == 0:
ans = 2 * ans
control = 1
else:
ans = 2 * ans
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN LIST VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST WHILE VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import time
def solve(n, m):
if n == 0:
return m + 1
if m < n:
return 0
lm = len(bin(m)) - 3
if lm > len(bin(n)) - 3:
res = solve(n, m - (1 << lm))
if len(bin(res)) - 3 == lm:
return 1 << lm + 1
else:
return res + (1 << lm)
res = solve(n - (1 << lm), m - (1 << lm))
if len(bin(res)) - 3 == lm:
return 1 << lm + 1
else:
return res
t = int(input())
for i in range(t):
n, m = list(map(int, input().split()))
print(solve(n, m)) | IMPORT FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR RETURN BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR RETURN BIN_OP NUMBER BIN_OP VAR NUMBER RETURN 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 two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | from sys import stdin, stdout
def get():
return stdin.readline().strip()
def getf(sp=" "):
return [int(i) for i in get().split(sp)]
def put(a, end="\n"):
stdout.write(str(a) + end)
def putf(a, sep=" ", end="\n"):
stdout.write(sep.join([str(i) for i in a]) + end)
def solve(n, m):
if n > m:
return 0
a = [0] + [int(i) for i in bin(m)[2:]]
b = [0] + [int(i) for i in bin(n)[2:]]
k = len(a)
b = [0] * (k - len(b)) + b
x = 10**12
for i in range(k):
if a[i] == 0:
a1 = a.copy()
a1[i] = 1
for j in range(i + 1, k):
a1[j] = b[j]
num_a = int("".join([str(j) for j in a1]), 2)
x = min(x, num_a ^ n)
return x
def main():
for _ in range(int(get())):
n, m = getf()
put(solve(n, m))
main() | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_DEF STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_DEF STRING STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
t = int(input())
def msb(x):
res = 0
while x > 0:
x >>= 1
res += 1
return res
def solve(n, m):
if n == 0:
return m + 1
if n > m:
return 0
n_msb = msb(n)
m_msb = msb(m)
if m_msb > n_msb:
return (m >> n_msb << n_msb) + solve(n, m & (1 << n_msb) - 1)
if m_msb == n_msb:
if m == (1 << n_msb) - 1:
return 1 << n_msb
else:
return solve(n - (1 << n_msb - 1), m - (1 << n_msb - 1))
for _ in range(t):
n, m = list(map(int, input().split()))
print(solve(n, m)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR NUMBER RETURN BIN_OP VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP BIN_OP NUMBER VAR NUMBER IF VAR VAR IF VAR BIN_OP BIN_OP NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR RETURN FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER 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 two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for _ in range(int(input())):
n, m = map(int, input().split())
k = 2**31
ans = 0
while k:
if k > m + 1:
if k <= n:
break
else:
pass
elif k == m + 1:
if k <= n:
break
else:
ans += k
break
elif k <= n:
n %= k
m %= k
else:
ans += k
n %= k
m %= k
k //= 2
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def MI():
return map(int, sys.stdin.buffer.readline().split())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
def li():
return [int(i) for i in input().split()]
def lli(rows):
return [li() for _ in range(rows)]
def si():
return input()
def ii():
return int(input())
def ins():
return input().split()
def solve(n, m):
s = 0
util, pre = [], []
for i in range(31):
if n & 1 << i == 0:
s += 1 << i
util.append(i)
pre.append(s)
diff = max(0, m - n + 1)
ans = 0
while diff > 0:
for i in range(len(util)):
if pre[i] >= diff:
ans |= 1 << util[i]
diff -= 1 << util[i]
break
return ans
t = II()
for _ in range(t):
n, m = MI()
print(solve(n, m)) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
def solve():
n, m = map(int, input().split())
res = 0
m += 1
for i in range(31, -1, -1):
mask = 1 << i
if n & mask < m & mask:
res += mask
if n & mask > m & mask:
break
print(res)
for _ in range(t):
solve() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER 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 EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def f(n):
l = []
while n > 0:
l.append(n % 2)
n //= 2
return l
def solve(n, m):
a = f(n)
b = f(m)
k = max(len(a), len(b))
for _ in range(k - len(a)):
a.append(0)
for _ in range(k - len(b)):
b.append(0)
for j in range(k - 1, -1, -1):
if a[j] == 1 and b[j] == 0:
return (n ^ m) // 2 ** (j + 1) * 2 ** (j + 1)
for j in range(k):
if a[j] == 0 and b[j] == 0:
return (n ^ m) // 2 ** (j + 1) * 2 ** (j + 1) + 2**j
return 2**k
t = int(input())
for i in range(t):
n, m = map(int, input().split())
print(solve(n, m)) | FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP NUMBER VAR RETURN BIN_OP NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def MI():
return map(int, sys.stdin.buffer.readline().split())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
def li():
return [int(i) for i in input().split()]
def lli(rows):
return [li() for _ in range(rows)]
def si():
return input()
def ii():
return int(input())
def ins():
return input().split()
def solve():
n, m = LI()
if m < n:
return 0
elif n == m:
if n % 2 == 0:
return 1
else:
c = 0
while n > 0:
if n % 2 == 0:
ans = c
break
n //= 2
c += 1
return 2**c
else:
nb = bin(n).lstrip("0b")
mb = bin(m).lstrip("0b")
nb = "0" * (len(mb) - len(nb)) + nb
l = len(nb)
sb = ""
for i in range(l):
if nb[i] <= mb[i]:
sb += str(int(nb[i]) ^ int(mb[i]))
else:
sb += "0" * (l - i)
return int(sb, 2)
else:
c = 0
while m > 0:
if n % 2 == 0 and m % 2 == 0:
ans = sb[: l - c - 1] + "1" + "0" * c
return int(ans, 2)
n //= 2
m //= 2
c += 1
else:
return 2**c
def main():
for _ in range(II()):
sys.stdout.write(str(solve()) + "\n")
main() | IMPORT ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR RETURN NUMBER IF VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP STRING BIN_OP VAR VAR RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER STRING BIN_OP STRING VAR RETURN FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN BIN_OP NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def solve():
n, m = map(int, input().split())
if n > m:
return 0
if n | m == m:
return n ^ (n | m + 1)
bm = bin(m)[2:]
bn = bin(n)[2:]
bn = "0" * (len(bm) - len(bn)) + bn
to_transform = list(bn)
for i in range(len(to_transform)):
if to_transform[i] == "1" and bm[i] == "0":
break
elif to_transform[i] == "0" and bm[i] == "1":
to_transform[i] = bm[i]
ans = n ^ (n | int("".join(to_transform), 2))
return ans
t = int(input())
for _ in range(t):
print(solve()) | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR RETURN NUMBER IF BIN_OP VAR VAR VAR RETURN BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for _ in range(int(input())):
n, m = map(int, input().split())
if m < n:
print(0)
else:
sn = ""
sm = ""
nn = n
mm = m + 1
ans = ""
an = 0
while nn > 0:
sn += str(nn % 2)
nn //= 2
while mm > 0:
sm += str(mm % 2)
mm //= 2
for _ in range(len(sm) - len(sn)):
sn += "0"
sn = sn[::-1]
sm = sm[::-1]
mm = len(sm)
if 2**mm - 1 == m:
print(2**mm)
else:
sb = "1" * mm
for i in range(mm):
if sb[i] == sm[i] and an <= m:
ans += sb[i]
else:
ans += sn[i]
an += int(ans[i]) * 2 ** (mm - 1 - i)
ans = ans[::-1]
print(an ^ n) | 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 VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP STRING VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
a, b = map(int, input().split())
if a > b:
print(0)
continue
b += 1
aa = bb = 0
R = a ^ b
for j in range(31):
bt = 1 << j
aa += a & bt
bb += b & bt
if aa >= bb:
R = min(a - aa ^ b - bb, R)
print(R) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR 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 NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for tc in range(t):
n, m = map(int, input().split())
m += 1
target = "0" * max(len(bin(n)[2:]) - len(bin(m)[2:]), 0) + bin(m)[2:]
current = "0" * max(len(bin(m)[2:]) - len(bin(n)[2:]), 0) + bin(n)[2:]
bink = "0b"
for i in range(len(current)):
if current[i] == target[i]:
bink += "0"
elif current[i] == "0" and target[i] == "1":
bink += "1"
elif current[i] == "1" and target[i] == "0":
break
bink += "0" * (len(current) - (len(bink) - 2))
print(int(bink, 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 VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR STRING IF VAR VAR STRING VAR VAR STRING VAR STRING IF VAR VAR STRING VAR VAR STRING VAR BIN_OP STRING BIN_OP FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for _ in range(t):
res = 0
n, m = map(int, input().split())
m += 1
for i in range(30, -1, -1):
if n >> i & 1 == m >> i & 1:
continue
if m >> i & 1:
res |= 1 << i
n |= 1 << i
if n >= m:
break
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
LogN = 30
def main():
N, M = map(int, input().split())
M += 1
Ans = 0
for i in range(LogN - 1, -1, -1):
if N >> i & 1:
if 1 << i < M:
M -= 1 << i
else:
break
elif 1 << i < M:
Ans += 1 << i
M -= 1 << i
elif 1 << i == M:
Ans += 1 << i
break
print(Ans)
T = int(input())
for _ in range(T):
main() | IMPORT ASSIGN VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR IF BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def bit(n):
res = []
while n:
res.append(n % 2)
n //= 2
return res
def tod(s):
res = 0
cur = 1
for i in range(len(s)):
res += s[i] * cur
cur *= 2
return res
for _ in range(int(input())):
n, m = map(int, input().split())
q = bit(n)
w = bit(m)
res = w[:]
if m < n:
print(0)
continue
ans = [(0) for _ in range(len(q))] + w[len(q) :]
pr = False
for i in range(len(q) - 1, -1, -1):
if q[i] == 1 and w[i] == 0:
pr = True
break
if q[i] == 0 and w[i] == 1:
ans[i] = 1
if not pr:
for i in range(len(ans)):
if i < len(q):
if ans[i] == 0 and q[i] == 0:
ans[i] = 1
for j in range(i - 1, -1, -1):
ans[j] = 0
break
elif ans[i] == 0:
ans[i] = 1
for j in range(i - 1, -1, -1):
ans[j] = 0
break
else:
ans = [(0) for _ in range(len(ans))] + [1]
ans = tod(ans)
print(ans) | FUNC_DEF ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP 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 ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def cal(n, m):
mex = 0
for i in range(31, -1, -1):
if n >> i & 1 == m >> i & 1:
continue
if m >> i & 1:
mex |= 1 << i
else:
break
return mex
for _ in range(int(input())):
n, m = map(int, input().split())
m += 1
mex = 0
if n <= m:
mex = cal(n, m)
print(mex) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | DEBUG = 0
if DEBUG == 1:
data = open("sample1.in", "r")
def readline():
if DEBUG == 1:
return data.readline().strip("\r\n")
else:
try:
return input().strip("\r\n")
except EOFError:
return ""
def readi():
return [int(t) for t in readline().split()]
(t,) = readi()
for id in range(t):
n, m = readi()
n = format(n, "032b")
p = format(m + 1, "032b")
k = [0] * 32
for i in range(31, -1, -1):
if n[i] == p[i]:
k[i] = 0
elif n[i] == "1" and p[i] == "0":
for j in range(i, 32):
k[j] = 0
else:
k[i] = 1
kk = ""
for i in range(32):
kk += str(k[i])
kk = int(kk, base=2)
print(kk)
if DEBUG == 1:
data.close() | ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING STRING FUNC_DEF IF VAR NUMBER RETURN FUNC_CALL FUNC_CALL VAR STRING RETURN FUNC_CALL FUNC_CALL VAR STRING VAR RETURN STRING FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING FOR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for _ in range(int(input())):
n, m = map(int, input().split())
ans = 0
for i in range(31, -1, -1):
x = 1 << i
a = x & n
b = x & m + 1
if a == 0:
if b == 0:
continue
else:
ans |= x
if a == x:
if b == 0:
break
else:
continue
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def read_line():
return [int(x) for x in input().split()]
def read_int():
return int(input())
def solve():
n, m = read_line()
m += 1
res = 0
for i in range(30, -1, -1):
bit = 1 << i
if n & bit != 0 and m & bit == 0:
break
if n & bit == 0 and m & bit != 0:
res = res | bit
print(res)
t = read_int()
while t > 0:
solve()
t -= 1 | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER 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 ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | for testis in range(int(input())):
n, m = map(int, input().split())
if m < n:
print(0)
else:
m = bin(m + 1)[2:]
n = "0" * (len(m) - len(bin(n)[2:])) + bin(n)[2:]
ans = ["0"] * len(m)
for i in range(len(m)):
if n[i] == m[i]:
ans[i] = "0"
elif n[i] == "1" and m[i] == "0":
break
else:
ans[i] = "1"
print(int("".join(ans), 2)) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR STRING IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def f(n, m, ind):
if n >= m:
return 0
if ind < 0:
return 0
if n >> ind & 1 == m >> ind & 1:
return f(n, m, ind - 1)
else:
return f(n | 1 << ind, m, ind - 1) | 1 << ind
for _ in range(int(input())):
n, m = map(int, input().split())
print(f(n, m + 1, len(bin(m + 1)) - 2)) | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER 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 BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
input = sys.stdin.readline
def solve():
n, m = map(int, input().split())
x = 0
lastzz = 32
for i in range(32, -1, -1):
base = 1 << i
if not n & base and not m & base:
lastzz = i
elif n & base and not m & base:
print(x)
return
elif not n & base and m & base:
x |= base
x |= 1 << lastzz
x &= ~((1 << lastzz) - 1)
print(x)
tc = int(input().strip())
for _ in range(tc):
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR RETURN IF BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def solve(n, m):
if n > m:
print(0)
return
result = 0
m += 1
a = bin(m)[2:]
b = bin(n)[2:]
if len(b) < len(a):
b = "0" * (len(a) - len(b)) + b
length = len(b)
for x in range(length):
if b[x] == "0" and a[x] == "1":
result += 2 ** (length - x - 1)
if b[x] == "1" and a[x] == "0":
break
print(result)
for _ in range(int(input())):
n, m = map(int, input().split())
solve(n, m) | FUNC_DEF IF VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR STRING VAR VAR STRING EXPR FUNC_CALL 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 EXPR FUNC_CALL VAR VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | t = int(input())
for _ in range(t):
n, m = map(int, input().split())
if n > m:
print(0)
else:
m += 1
binLstOfm = list(map(int, bin(m)[2:]))
binLstOfn = list(map(int, bin(n)[2:]))
binLstOfn = [0] * (len(binLstOfm) - len(binLstOfn)) + binLstOfn
s = ""
for i in range(len(binLstOfm)):
if binLstOfm[i] == 0 and binLstOfn[i] == 1:
break
if binLstOfm[i] == 1 and binLstOfn[i] == 0:
s += "1"
else:
s += "0"
while len(s) < len(binLstOfm):
s += "0"
print(int(s, 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 IF VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR STRING VAR STRING WHILE FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | import sys
t = int(input())
for _ in range(t):
n, m = list(map(int, sys.stdin.readline().strip().split()))
if n > m:
print(0)
else:
bin_n = list(map(int, bin(n)[:1:-1]))
bin_m = list(map(int, bin(m)[:1:-1]))
bin_m.append(0)
changeable = []
min_diff = m - n
diff_now = 0
for pos in range(len(bin_m)):
if pos < len(bin_n) and bin_n[pos] == 0:
changeable.append(2**pos)
diff_now += changeable[-1]
elif pos >= len(bin_n):
changeable.append(2**pos)
diff_now += changeable[-1]
if diff_now > min_diff:
break
for c in changeable[::-1]:
if diff_now - c > min_diff:
diff_now -= c
print(diff_now) | IMPORT 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 FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR VAR FOR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator .
$\operatorname{MEX}$ of the sequence of non-negative integers is the smallest non-negative integer that doesn't appear in this sequence. For example, $\operatorname{MEX}(0, 1, 2, 4) = 3$, and $\operatorname{MEX}(1, 2021) = 0$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 30000$) β the number of test cases.
The first and only line of each test case contains two integers $n$ and $m$ ($0 \le n, m \le 10^9$).
-----Output-----
For each test case, print a single integer β the answer to the problem.
-----Examples-----
Input
5
3 5
4 6
3 2
69 696
123456 654321
Output
4
3
0
640
530866
-----Note-----
In the first test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2, 3 \oplus 3, 3 \oplus 4, 3 \oplus 5$, or $3, 2, 1, 0, 7, 6$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $4$.
In the second test case, the sequence is $4 \oplus 0, 4 \oplus 1, 4 \oplus 2, 4 \oplus 3, 4 \oplus 4, 4 \oplus 5, 4 \oplus 6$, or $4, 5, 6, 7, 0, 1, 2$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $3$.
In the third test case, the sequence is $3 \oplus 0, 3 \oplus 1, 3 \oplus 2$, or $3, 2, 1$. The smallest non-negative integer which isn't present in the sequence i. e. the $\operatorname{MEX}$ of the sequence is $0$. | def process(n, m):
if n > m:
return [0, 0]
n1 = bin(n)[2:]
m1 = bin(m)[2:]
n1 = n1.zfill(len(m1))
n1 = n1[::-1]
m1 = m1[::-1]
answer = 0
is_good = None
for i in range(len(m1)):
if n1[i] == "1" and m1[i] == "0":
is_good = i
if is_good is None:
first_zero = None
for i in range(len(m1)):
if m1[i] == "0":
first_zero = i
break
if first_zero is None:
return [2 ** len(m1), 0]
answer = 2**first_zero
for i in range(first_zero + 1, len(m1)):
if m1[i] == "1" and n1[i] == "0":
answer += 2**i
return [answer, 0]
for i in range(len(m1)):
if i > is_good and n1[i] == "0" and m1[i] == "1":
answer += 2**i
return [answer, 1]
t = int(input())
for i in range(t):
n, m = [int(x) for x in input().split()]
print(process(n, m)[0]) | FUNC_DEF IF VAR VAR RETURN LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING ASSIGN VAR VAR IF VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR IF VAR NONE RETURN LIST BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR BIN_OP NUMBER VAR RETURN LIST VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR STRING VAR VAR STRING VAR BIN_OP NUMBER VAR RETURN LIST VAR NUMBER 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 NUMBER |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.