description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = dict.fromkeys(range(30), 0)
for i in range(n):
x = bin(a[i]).replace("0b", "")
p = len(x)
for j in range(p):
if x[p - j - 1] == "1":
d[j] += pow(2, j)
l = [(0) for i in range(30)]
m = list(d.values())
m.sort(reverse=True)
for i in range(k):
for j in d:
if d[j] == m[i]:
l[j] = 1
d[j] = -1
break
count = 0
for i in range(len(l)):
if l[i] == 1:
count += pow(2, i)
print(count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER STRING VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
try:
for _ in range(int(input())):
n, k = list(map(int, input().split(" ")))
A = list(map(int, input().split(" ")))
contrOfEachPlc = [0] * 31
for i in range(n):
a = format(A[i], "031b")
A[i] = a
po = 30
for i in range(31):
for j in range(n):
contrOfEachPlc[i] += int(A[j][i])
contrOfEachPlc[i] = contrOfEachPlc[i] * pow(2, po)
po -= 1
reversingContrOfEachPlc = [0] * 31
pos = 0
d = {}
for i in range(30, -1, -1):
reversingContrOfEachPlc[pos] = contrOfEachPlc[i]
d[pos] = reversingContrOfEachPlc[pos]
pos += 1
d = sorted(d.items(), key=lambda kv: (kv[1], kv[0]), reverse=True)
x = 0
lst = []
i = 0
while i < 30:
if d[i][1] > 0:
flag = 0
srt = i
while d[i][1] == d[i + 1][1]:
flag = 1
i += 1
if flag == 1:
for a in range(i, srt - 1, -1):
lst.append(d[a])
i += 1
if flag == 0:
lst.append(d[i])
i += 1
else:
break
for i in range(30, -1, -1):
if d[i][1] == 0:
lst.append(d[i])
for i in range(k):
x += pow(2, lst[i][0])
print(x)
except:
pass
|
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 STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
high_bits = [(0) for i in range(30)]
for i in arr:
bin_n = bin(i)[2:]
bin_n = bin_n[::-1]
for index, bit in enumerate(bin_n):
if bit == "1":
high_bits[index] += 1
high_include = 0
ans_arr = []
for pow, frq in enumerate(high_bits):
ans_arr.append([2**pow * frq, pow])
ans_arr.sort(key=lambda x: x[0], reverse=True)
ans = 0
while high_include < k:
ans += 2 ** ans_arr[high_include][-1]
high_include += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = list(map(int, input().split()))
l = list(map(int, input().split()))
s = []
x = len(bin(max(l))[2:])
for i in l:
y = bin(i)[2:]
y = (x - len(y)) * "0" + y
s.append(y)
y = []
for i in range(x):
z = ""
for j in range(n):
z += s[j][i]
y.append(z)
s = []
for i in range(x):
p = [y[i].count("1") * 2 ** (x - 1 - i), i]
s.append(p)
s.sort(reverse=True)
res = [(0) for i in range(x)]
for i in range(min(k, x)):
res[s[i][1]] = 1
ans = ""
for i in res:
ans += str(i)
ans = "1" * (k - min(k, x)) + ans
print(int(ans, 2))
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR STRING VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST BIN_OP FUNC_CALL VAR VAR STRING BIN_OP NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 30
for j in a:
c = j
r = 0
while c:
b[r] += c % 2
c //= 2
r += 1
u = []
s = 1
for z in range(30):
b[z] *= s
u.append(b[z])
s *= 2
u.sort(reverse=True)
d = []
ans = 0
for p in range(k):
h = u[p]
for r in range(30):
if b[r] == h and r not in d:
d.append(r)
break
ans += 2**r
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
maximum = max(a)
maxLength = len(bin(maximum)) - 2
if k >= maxLength:
print(2**k - 1)
else:
oneCount = [(0) for i in range(maxLength)]
for num in a:
reversedBinary = bin(num)[2:][::-1]
for i, bit in enumerate(reversedBinary):
oneCount[i] += int(bit)
weights = []
base = 0
for count in oneCount:
weights.append(count * 2**base)
base += 1
x = 0
for i in range(k):
index = weights.index(max(weights))
x += 2**index
weights[index] = -1
print(x)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)
s = bin(m)[2:]
l = len(s)
v = []
for i in range(n):
p = bin(a[i])[2:]
v.append(p)
z = [0] * l
for i in range(n):
for j in range(len(v[i]) - 1, -1, -1):
if v[i][j] == "1":
z[len(v[i]) - 1 - j] += 1
v = []
for i in range(l):
v.append(2**i * z[i])
ans = 0
if k > l:
for i in range(l, k):
ans += 2**i
for i in range(l):
mi = v.index(max(v))
ans += 2**mi
v[mi] = -1
else:
for i in range(k):
mi = v.index(max(v))
ans += 2**mi
v[mi] = -1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR STRING VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
def binary(x):
l = []
while x >= 1:
rem = x % 2
x = x // 2
l.append(rem)
return l
for i in range(int(input())):
a, k = map(int, input().split())
m = []
l = []
p = list(map(int, input().split()))
for c in p:
m.append(binary(c))
count = 0
for i in range(30):
for j in range(len(m)):
if len(m[j]) > i:
if m[j][i] == 1:
count += 1
l.append([count * 2**i, i])
count = 0
l = sorted(l, key=lambda x: x[0], reverse=True)
c = 0
for i in range(k):
c += 2 ** l[i][1]
print(c)
|
FUNC_DEF ASSIGN VAR LIST WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
def Solve(k, arr):
a = [0] * 30
s = ""
for i in range(len(arr)):
s = bin(arr[i])[2:]
j = 0
for ones in range(len(s) - 1, -1, -1):
if s[ones] == "1":
a[j] += 1
j += 1
sums = [0] * 30
kk = 0
for i in a:
sums[kk] = i * 2**kk
kk += 1
vals = sorted(zip(sums, range(len(sums))), key=lambda x: x[0], reverse=True)
if k == 1:
return 2 ** vals[0][1]
elif k == 2:
return 2 ** vals[0][1] + 2 ** vals[1][1]
else:
out = 0
for i in range(k):
out += 2 ** vals[i][1]
return out
T = int(input())
for _ in range(T):
n, k = map(int, input().split())
arr = list(map(int, input().split()))
print(Solve(k, arr))
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR STRING VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP NUMBER VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(int(input()))):
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = [(0) for i in range(30)]
for i in a:
for j in range(30):
f[j] += i >> j & 1
vals = []
for i in range(30):
vals.append((f[i] * (1 << i), -i))
vals.sort(reverse=True)
res = 0
for i in range(k):
res |= 1 << -vals[i][1]
print(res)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
t = int(input())
for i in range(t):
a = list(input().split())
n = int(a[0])
kk = int(a[1])
a = list(input().split())
dic = {}
for k in a:
m = int(k)
c = -1
while m > 0:
c += 1
if m & 1 == 1:
dic[c] = dic.get(c, 0) + pow(2, c)
else:
dic[c] = dic.get(c, 0)
m = m >> 1
dic_l = sorted(dic, key=lambda x: (-dic[x], x))
co = 0
res = 0
for k in dic_l:
res = res + pow(2, k)
co = co + 1
if co == kk:
break
while co != kk:
res = res + pow(2, co)
co = co + 1
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
_map = {i: (0) for i in range(31)}
for val in a:
i = 0
while val > 0:
if val & 1:
_map[i] += 1
val = val >> 1
i += 1
arr = []
for i in range(31):
arr.append((_map[i] * (1 << i), i))
arr.sort(reverse=True, key=lambda x: (x[0], -x[1]))
ans = 0
for i in range(k):
ans = ans ^ 1 << arr[i][1]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for t in range(int(input())):
n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
pairs = []
for b in range(30):
mysum = 0
for i in range(len(arr)):
if arr[i] >> b & 1 == 1:
mysum += 2**b
pairs.append((mysum, 50 - b))
pairs.sort(reverse=True)
mynum = 0
for i in range(k):
mynum += 2 ** (50 - pairs[i][1])
print(mynum)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
final = []
for i in range(31):
final.append([0, -i, 0])
for x in a:
tmp = bin(x)[2:]
tmp = tmp[::-1]
for i in range(len(tmp)):
if tmp[i] == "1":
final[i][2] += 1
final[i][0] += 1 << i
final.sort(reverse=True)
ans = 0
for i in range(k):
ans |= 1 << abs(final[i][1])
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR NUMBER NUMBER VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * 30
c = [0] * 30
power = 2**29
for i in range(30):
c[i] = power
power = power // 2
for i in a:
s = bin(i).replace("0b", "")
l = len(s)
j = -1
while l > 0:
if s[j] == "1":
b[j] += 1
j -= 1
l -= 1
d = [0] * 30
for i in range(30):
d[i] = b[i] * c[i]
count = 0
for i in range(k):
m = max(d)
l = len(d)
j = -1
while l > 0:
if d[j] == m:
count += c[j]
del c[j]
del d[j]
break
l -= 1
j -= 1
print(count)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR STRING VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
def to_bin(num, pad=None):
bin_rep = []
i = 0
while True:
if num < 2**i:
break
if num & 2**i:
bin_rep.append(1)
else:
bin_rep.append(0)
i += 1
if pad:
while len(bin_rep) < pad:
bin_rep.append(0)
return bin_rep
for _ in range(int(input())):
n, set_b = list(map(int, input().split()))
nums = list(map(int, input().split()))
req_len = len(to_bin(max(nums)))
all_bin = [to_bin(i, req_len) for i in nums]
if req_len < set_b:
x = 0
for i in range(set_b):
x += 2**i
else:
count_pos = [[0, i] for i in range(req_len)]
for i in range(req_len):
for j in range(len(all_bin)):
count_pos[i][0] += all_bin[j][i] * 2**i
count_pos.sort(key=lambda x: (-x[0], x[1]))
x = 0
for i in range(set_b):
x += 2 ** count_pos[i][1]
print(x)
|
FUNC_DEF NONE ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE NUMBER IF VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR NUMBER IF VAR WHILE FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER BIN_OP VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
arr = list(map(lambda x: bin(int(x))[2:], input().split()))
arr = list(map(lambda x: "0" * (32 - len(str(x))) + str(x), arr))
y = [0] * 32
for i in range(32):
for ele in arr:
y[i] += int(ele[i])
arr1 = []
for i in range(32):
ans = int(y[i]) * pow(2, 31 - i)
arr1.append([31 - i, ans])
gain = sorted(arr1, key=lambda x: x[1])[::-1]
ans = 0
for i in range(k):
ans += pow(2, gain[i][0])
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP STRING BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
t = int(input())
for i in range(t):
n, k = map(int, input().split())
a = [bin(int(x)).replace("0b", "") for x in input().split()]
num = [(0) for x in range(30)]
for j in a:
for m in range(len(j)):
ti = len(j) - 1 - m
if j[ti] == "1":
num[m] += 1
d = {}
for j in range(30):
num[j] *= pow(2, j)
d[j] = num[j]
sorte = sorted(d.items(), key=lambda x: x[1], reverse=True)
total = 0
for j in range(k):
total += pow(2, sorte[j][0])
print(total)
|
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 FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR STRING VAR VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
bits = [[] for i in range(35)]
for i in range(n):
temp = a[i]
for j in range(35):
bits[j].append(temp % 2)
temp //= 2
profit = []
for i in range(35):
profit.append(bits[i].count(1) * 2**i)
x = [(0) for i in range(35)]
for i in range(k):
maximum, index = 0, -1
for j in range(35):
if profit[j] > maximum:
index = j
maximum = profit[j]
if maximum > 0:
x[index] = 1
profit[index] = -1
else:
for j in range(35):
if x[j] == 0:
x[j] = 1
break
final_x = 0
for i in range(34, -1, -1):
final_x *= 2
final_x += x[i]
print(final_x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
t = int(input())
for _ in range(t):
n, k = list(map(lambda x: int(x), input().split()))
a = list(map(lambda x: int(x), input().split()))
values = {i: (0) for i in range(0, 32)}
for number in a:
for i, bit in enumerate(bin(number)[2:][::-1]):
if bit == "1":
values[i] += 1
all_values = []
for pos in values:
all_values.append((pow(2, pos) * values[pos], pos))
all_values.sort(key=lambda x: x[0], reverse=True)
string = ["0"] * 32
for value in all_values[0:k]:
string[value[1]] = "1"
print(int("".join(string[::-1]), 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR STRING VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER FOR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
def binary(array, k):
bits = [(0) for i in range(32)]
for i in range(len(array)):
j = 31
while array[i] != 0:
a = array[i] % 2
array[i] = array[i] // 2
bits[j] += a
j -= 1
j = 0
for i in range(len(bits) - 1, -1, -1):
bits[i] = bits[i] * pow(2, j)
j += 1
for i in range(len(bits) // 2):
bits[i], bits[len(bits) - 1 - i] = bits[len(bits) - 1 - i], bits[i]
bits = sorted(zip(bits, range(32)), key=lambda x: x[0], reverse=True)
if k == 1:
return 2 ** bits[0][1]
elif k == 2:
return 2 ** bits[0][1] + 2 ** bits[1][1]
else:
out = 0
for i in range(k):
out += 2 ** bits[i][1]
return out
t = int(input())
for _ in range(t):
n, k = input().split()
n = int(n)
k = int(k)
array = [int(temp) for temp in input().split()]
print(binary(array, k))
|
FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR NUMBER 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 BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP NUMBER VAR NUMBER NUMBER IF VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
test = int(input())
for _ in range(test):
n, k = map(int, input().split())
a = list(map(int, input().split()))
count = [[0, i] for i in range(64)]
for i in a:
for j in range(64):
count[-1 - j][0] += (i >> j & 1) * 2**j
count.sort(reverse=True)
num = ["0"] * 64
for k in range(k):
num[count[k][1]] = "1"
print(int("".join(num), 2))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST STRING NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chef's good friend Shubham has an assignment to complete, but he is too lazy to do it, so he asked Chef to help him. On the other hand, Chef was busy in the kitchen, so he in turn asked you to help Shubham.
You are given a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. For any positive integer $X$ such that exactly $K$ bits in the binary representation of $X$ are equal to $1$, consider the sum $S = \sum_{i=1}^N (X \wedge A_{i})$; here, $\wedge$ denotes bitwise AND. You should choose $X$ in such a way that $S$ is maximum possible. If there is more than one such value of $X$, you should find the smallest one.
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $K$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$.
------ Output ------
For each test case, print a single line containing one integer ― the smallest possible value of $X$.
------ Constraints ------
$1 ≤ T ≤ 1,000$
$1 ≤ N ≤ 10^{5}$
$1 ≤ K ≤ 30$
$1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (50 points): $K ≤ 2$
Subtask #2 (50 points): original constraints
----- Sample Input 1 ------
1
4 1
3 4 5 1
----- Sample Output 1 ------
4
----- explanation 1 ------
Example case 1: Exactly one bit in $X$ should be $1$. Our options are:
- If $X = 1$, $S = 1+0+1+1 = 3$.
- If $X = 2$, $S = 2+0+0+0 = 2$.
- If $X = 4$, $S = 0+4+4+0 = 8$.
- For any greater valid $X$, $S = 0$.
The maximum value of $S$ is $8$, so the answer is the only value of $X$ where we get $S = 8$.
|
for _ in range(int(input())):
n, k = map(int, input().split())
arr = [int(k) for k in input().split()]
bits = [0] * 30
for i in range(n):
for j in range(0, 30):
if arr[i] & 1 << j:
bits[j] += 1
sm = [0] * 30
for i in range(30):
sm[i] = bits[i] * (1 << i)
tup = []
for i in range(30):
tup.append([sm[i], i])
tup = sorted(tup, key=lambda x: -x[0])
ans = 0
for i in range(k):
ans += 1 << tup[i][1]
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
for z in range(int(input())):
n = int(input())
a = input()
b = input()
p, q, r = 0, 0, 0
for c in a:
if c == "1":
p += 1
for c in b:
if c == "1":
q += 1
if p > q:
h = p
g = q
j = n - p
else:
h = q
g = p
j = n - q
mn = h - g
m = min(g, j)
num = [0] * (n + 1)
den = [0] * (n + 1)
c = [0] * (n + 1)
num[0] = den[0] = c[0] = 1
for i in range(n):
num[i + 1] = num[i] * (n - i) % 1000000007
den[i + 1] = den[i] * (i + 1) % 1000000007
c[i + 1] = num[i + 1] * pow(den[i + 1], 1000000007 - 2, 1000000007) % 1000000007
for i in range(m + 1):
r += c[mn]
mn += 2
print(r % 1000000007)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
fact = []
N = 10**5 + 1
fact.append(1)
mod = 10**9 + 7
for i in range(1, N):
fact.append(fact[i - 1] * i % mod)
for _ in range(int(input())):
n = int(input())
a = input()
b = input()
x1 = a.count("1")
x0 = n - x1
y1 = b.count("1")
y0 = n - y1
if x1 == 0 or x0 == 0:
qq = fact[n]
c1 = y1
i1 = int(pow(fact[n - c1], mod - 2, mod))
i2 = int(pow(fact[c1], mod - 2, mod))
qq = qq * i1 * i2 % mod
print(qq)
continue
if y1 == 0 or y0 == 0:
qq = fact[n]
c1 = x1
i1 = int(pow(fact[n - c1], mod - 2, mod))
i2 = int(pow(fact[c1], mod - 2, mod))
qq = qq * i1 * i2 % mod
print(qq)
continue
a = x1 * "1"
a = a + x0 * "0"
b = y0 * "0"
b += "1" * y1
c1, c0 = 0, 0
for i in range(n):
if a[i] != b[i]:
c1 += 1
else:
c0 += 1
d = max(x1, y1) - min(x1, y1)
res = 0
while c1 >= d:
qq = fact[n]
i1 = int(pow(fact[n - c1], mod - 2, mod))
i2 = int(pow(fact[c1], mod - 2, mod))
qq = qq * i1 * i2 % mod
c1 -= 2
c0 += 2
res = (res + qq) % mod
print(res)
|
ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR BIN_OP VAR STRING ASSIGN VAR BIN_OP VAR STRING VAR BIN_OP STRING VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
fact = []
fact.append(1)
for j in range(1, 100001):
fact.append(j % 1000000007 * (fact[j - 1] % 1000000007) % 1000000007)
T = int(input())
while T:
n = int(input())
a = input()
b = input()
a1 = int(a.count("1"))
b1 = int(b.count("1"))
k = int(0)
m = 1000000007
if a1 == b1:
k = 1
if a1 == n and b1 == 0 or a1 == 0 and b1 == n:
print(1)
continue
x = int(a1 + b1)
if b1 <= n - a1:
x = x
else:
x = 2 * n - x
if (a1 + b1) % 2 == 0:
for i in range(max(2, abs(a1 - b1)), x + 1, 2):
k = k + fact[n] % m * pow(fact[n - i] * fact[i] % 1000000007, m - 2, m) % m
k = k % m
else:
for i in range(max(1, abs(a1 - b1)), x + 1, 2):
k = k + fact[n] % m * pow(fact[n - i] * fact[i] % 1000000007, m - 2, m) % m
k = k % m
print(k)
T = T - 1
|
ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def cones(s):
o = 0
for i in s:
if i == "1":
o += 1
return o
def pul(a, b, c):
a1 = 1
b1 = a
while b > 0:
if b % 2 == 1:
a1 = a1 * b1
if a1 > c:
a1 = a1 % c
b1 = b1**2
if b1 > c:
b1 = b1 % c
b = b // 2
return a1
def nCr(n, t, m):
return f[n] * (pul(f[t], m - 2, m) * pul(f[n - t], m - 2, m) % m) % m
f = [(0) for x in range(100004)]
f[0] = 1
for i in range(1, 100002):
f[i] = f[i - 1] * i % 1000000007
test = int(input())
while test > 0:
test -= 1
res = 0
n = int(input())
a = input()
b = input()
coua = cones(a)
coub = cones(b)
t = coua + coub
if coua == coub:
res = 1
while t >= abs(coua - coub):
if t == n:
if t == coua + coub:
res = (res + nCr(n, t, 1000000007)) % 1000000007
if t < n:
if t > 0 and t <= 2 * n - coua - coub:
res = (res + nCr(n, t, 1000000007)) % 1000000007
t -= 2
print(res % 1000000007)
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER IF VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def ncr(n, r, p):
num = den = 1
for i in range(r):
num = num * (n - i) % p
den = den * (i + 1) % p
return num * pow(den, p - 2, p) % p
def onesList(a, b, n):
maxi = max(a, b)
mini = min(a, b)
p = 2 * n - (a + b)
if a + b <= n:
return list(range(maxi - mini, maxi + mini + 1, 2))
else:
return list(range(maxi - mini, p + 1, 2))
def InverseofNumber(p):
naturalNumInverse[0] = naturalNumInverse[1] = 1
for i in range(2, N + 1, 1):
naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p
def Binomial(N, R, p):
ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
return ans
def InverseofFactorial(p):
factorialNumInverse[0] = factorialNumInverse[1] = 1
for i in range(2, N + 1, 1):
factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p
def factorial(p):
fact[0] = 1
for i in range(1, N + 1):
fact[i] = fact[i - 1] * i % p
try:
N = 1000001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * (N + 1)
p = 1000000007
InverseofNumber(p)
InverseofFactorial(p)
factorial(p)
t = int(input())
for i in range(t):
n = int(input())
a = input()
b = input()
l = onesList(a.count("1"), b.count("1"), n)
ans = 0
for i in l:
ans += Binomial(n, i, 1000000007) % 1000000007
print(ans % 1000000007)
except:
pass
|
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def comb(n, k):
if k > n - k:
k = n - k
val = 1
for i in range(k):
val = val * (n - i)
val = val // (i + 1)
return val
t = int(input())
while t > 0:
t -= 1
n = int(input())
a = input()
b = input()
a1 = a.count("1")
b1 = b.count("1")
one_diff = abs(a1 - b1)
if a1 + b1 <= n:
bloo = a1 + b1
else:
bla = a1 + b1 - n
bloo = a1 + b1 - 2 * bla
count = comb(n, one_diff)
ans = count
for i in range(one_diff + 2, bloo + 1, 2):
count = count * ((n - i + 1) * (n - i + 2)) // ((i - 1) * i)
ans += count
print(ans % 1000000007)
|
FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
fact = [1, 1]
for k in range(2, 100001):
fact.append(k * fact[k - 1] % 1000000007)
def invMod(number):
return pow(number, 1000000005, 1000000007)
for _ in range(int(input())):
n = int(input())
str1 = input().strip()
str2 = input().strip()
p = 1000000007
c0A = str1.count("0")
c1A = n - c0A
c0B = str2.count("0")
c1B = n - c0B
min1 = abs(c1A - c1B)
max1 = min(c1A, c0B) + min(c0A, c1B)
nf = fact[n]
res = 0
for i in range(min1, max1 + 1, 2):
res = (res + nf * invMod(fact[i] * fact[n - i]) % p) % p
print(res)
|
ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
mod = 10**9 + 7
fact = [1]
for i in range(1, 10**5 + 10):
fact.append(fact[i - 1] * i % mod)
def modularExponentiation(x):
n = mod - 2
result = 1
while n > 0:
if n % 2 == 1:
result = result * x % mod
x = x * x % mod
n = n // 2
return result
for _ in range(int(input())):
n = int(input())
a = input().count("1")
b = input().count("1")
min1 = abs(a - b)
if a + b <= n:
max1 = a + b
else:
max1 = 2 * n - (a + b)
count = 0
for i in range(min1, max1 + 1, 2):
count += (
modularExponentiation(fact[n - i]) * modularExponentiation(fact[i]) % mod
)
count = fact[n] % mod * count % mod
print(int(count))
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def ncr(n, min1, max1, p):
res = 0
num = 1
den = 1
if min1 == 0:
res = 1
for i in range(max1):
num = num * (n - i) % p
den = den * (i + 1) % p
if i - min1 >= -1 and (i - min1 + 1) % 2 == 0:
res = (res + num * pow(den, p - 2, p)) % p
return res
t = int(input())
p = 10**9 + 7
while t > 0:
t -= 1
n = int(input())
a = input().strip()
b = input().strip()
a_1 = 0
b_1 = 0
for i in a:
if i == "1":
a_1 += 1
for i in b:
if i == "1":
b_1 += 1
max1 = n - abs(n - (a_1 + b_1))
min1 = max(a_1, b_1) - min(a_1, b_1)
print(ncr(n, min1, max1, p))
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
mod = 10**9 + 7
def add(a, b):
return (a % mod + b % mod) % mod
def mul(a, b):
return a % mod * (b % mod) % mod
def ncr(n, r):
return mul(fact[n], mul(pow(fact[n - r], mod - 2, mod), pow(fact[r], mod - 2, mod)))
def answer():
ca1 = a.count("1")
cb1 = b.count("1")
o = abs(ca1 - cb1)
stop = abs(min(ca1, cb1) - min(n - ca1, n - cb1))
ans = 0
for i in range(n - o, stop - 1, -2):
ans = add(ans, ncr(n, i))
return ans
fact = [1]
for i in range(1, 10**5 + 1):
fact.append(mul(fact[-1], i))
for T in range(int(input())):
n = int(input())
a = input()
b = input()
print(answer())
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
t = int(input())
def fact(n):
if n == 0 or n == 1:
return 1
ans = 1
for i in range(1, n + 1):
ans = ans * i
return ans
def ncr(n, r):
p = 10**9 + 7
num = den = 1
for i in range(r):
num = num * (n - i) % p
den = den * (i + 1) % p
return num, den
def find(n, max_0, min_1, max_1, min_0):
num, den = ncr(n, min_1)
p = 10**9 + 7
add = num * pow(den, p - 2, p) % p
ans = add
for x in range(min_1 + 2, max_1 + 1, 2):
num = num * (n - (x - 2)) % p * (n - (x - 1)) % p
den = den * (x - 1) % p * x % p
add = num * pow(den, p - 2, p) % p
ans += add
return ans
for loop in range(t):
n = int(input())
a = input()
b = input()
x1 = 0
y1 = 0
x2 = 0
y2 = 0
for c in a:
if c == "1":
x1 += 1
else:
y1 += 1
for c in b:
if c == "1":
x2 += 1
else:
y2 += 1
max_1 = min(x1, y2) + min(x2, y1)
max_0 = min(x1, x2) + min(y2, y1)
min_0 = n - max_1
min_1 = n - max_0
ans = find(n, max_0, min_1, max_1, min_0)
print(int(ans) % (10**9 + 7))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
t = int(input())
while t:
t -= 1
n = int(input())
a = input().strip()
b = input().strip()
na = 0
nb = 0
for i in a:
if i == "1":
na += 1
for i in b:
if i == "1":
nb += 1
mil = abs(na - nb)
mal = min(na, n - nb) + min(nb, n - na)
sum = 0
p = 1000000007
num = den = 1
for i in range(mil):
num = num * (n - i) % p
den = den * (i + 1) % p
ini = num * pow(den, p - 2, p) % p
sum = ini
for i in range(mil + 2, mal + 1, 2):
num = num * (n - (i - 2)) % p
den = den * (i - 1) % p
num = num * (n - i + 1) % p
den = den * i % p
ini = num * pow(den, p - 2, p) % p
sum = (sum + ini) % 1000000007
print(sum)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
M = 1000000007
fact = [0] * 2000001
fact[0] = 1
for i in range(1, 2000001):
fact[i] = fact[i - 1] % M * (i % M) % M
def ncr(List, N):
Summation = 0
for i in List:
Summation += fact[N] * pow(fact[i], M - 2, M) * pow(fact[N - i], M - 2, M) % M
return Summation % M
for _ in range(int(input())):
N = int(input())
X = input()
Y = input()
A = X.count("1")
B = Y.count("1")
if A + B > N:
Max = N - A + (N - B)
else:
Max = A + B
Min = abs(A - B)
List = []
for i in range(Min, Max + 1, 2):
List.append(i)
print(ncr(List, N))
|
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
p = 1000000007
fac = [0] * 150001
fac[0] = 1
for i in range(1, 150001):
fac[i] = fac[i - 1] * i % p
t = int(input())
for _ in range(t):
ans = 0
n = int(input())
a = input()
b = input()
c1 = a.count("1")
c2 = b.count("1")
if n < c1 + c2:
Max = 2 * n - c1 - c2
else:
Max = c1 + c2
Min = abs(c1 - c2)
for j in range(Min, Max + 1, 2):
ans += fac[n] * pow(fac[j], p - 2, p) * pow(fac[n - j], p - 2, p) % p
ans = ans % p
print(ans)
|
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def ncr(n, mini, maxi):
p = 1000000007
num = 1
den = 1
for i in range(mini):
num = num * (n - i) % p
den = den * (i + 1) % p
final = num * pow(den, p - 2, p) % p
flag = 1
for i in range(mini, maxi):
num = num * (n - i) % p
den = den * (i + 1) % p
if flag % 2 == 0:
final += num * pow(den, p - 2, p) % p
flag += 1
return final
test = int(input())
for t in range(test):
n = int(input())
A = input()
B = input()
a = 0
b = 0
for i in range(n):
if A[i] == "1":
a += 1
if B[i] == "1":
b += 1
if a + b <= n:
high = a + b
else:
high = 2 * n - (a + b)
low = abs(b - a)
lol = ncr(n, low, high)
print(lol % 1000000007)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
p = 1000000007
Facts = []
Facts.append(1)
for z in range(1, 100001):
Facts.append(z % 1000000007 * (Facts[z - 1] % 1000000007) % 1000000007)
for _ in range(int(input())):
n = int(input())
A = str(input())
B = str(input())
ones_A = A.count("1")
ones_B = B.count("1")
if ones_A == n and ones_B == 0 or ones_A == 0 and ones_B == n:
ans = 1
else:
ans = 0
zeroes_A = n - ones_A
zeroes_B = n - ones_B
max_ones_A = max(ones_A, ones_B)
min_zeroes_A = min(zeroes_A, zeroes_B)
min_ones = min(ones_A, ones_B)
if min_zeroes_A >= min_ones:
for i in range(0, min_ones + 1):
r = max_ones_A - i + (min_ones - i)
ans = (
ans
+ Facts[n]
* pow(Facts[r], p - 2, p)
* pow(Facts[n - r], p - 2, p)
% p
) % p
else:
temp = min_ones - min_zeroes_A
for i in range(temp, min_ones + 1):
r = max_ones_A - i + (min_ones - i)
ans = (
ans
+ Facts[n]
* pow(Facts[r], p - 2, p)
* pow(Facts[n - r], p - 2, p)
% p
) % p
print(int(ans))
|
ASSIGN VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
N = 100001
p = 1000000007
factorial = [None] * (N + 1)
natural = [None] * (N + 1)
fact = [None] * (N + 1)
natural[0] = natural[1] = 1
for i in range(2, N + 1, 1):
natural[i] = natural[p % i] * (p - int(p / i)) % p
factorial[0] = factorial[1] = 1
for i in range(2, N + 1, 1):
factorial[i] = natural[i] * factorial[i - 1] % p
fact[0] = 1
for i in range(1, N + 1):
fact[i] = fact[i - 1] * i % p
for _ in range(int(input())):
n = int(input())
p = 1000000007
a = input()
b = input()
a1 = a.count("1")
a0 = n - a1
b0 = b.count("0")
b1 = n - b0
ans = 0
start = n - min(a1, b1) - min(a0, b0)
end = min(a0, b1) + min(a1, b0)
for i in range(start, end + 1, 2):
ans = (ans + fact[n] * factorial[i] % p * factorial[n - i] % p) % p
print(ans)
|
ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
t = int(input())
MODULO = 10**9 + 7
fact = [(0) for x in range(10**5 + 2)]
fact[0] = 1
for i in range(1, 10**5 + 2):
fact[i] = fact[i - 1] * i % MODULO
def inverse_mult(x, pow, mod):
a = 1
b = x
while pow > 0:
if pow % 2 == 1:
a *= b
if a > mod:
a %= mod
b **= 2
if b > mod:
b %= mod
pow //= 2
return a
def nCr(n, r, m):
return (
fact[n]
* (inverse_mult(fact[r], m - 2, m) * inverse_mult(fact[n - r], m - 2, m))
% m
% m
)
while t > 0:
t -= 1
m = int(input())
a = input().strip()
b = input().strip()
a1 = sum([(1 if x == "1" else 0) for x in a])
b1 = sum([(1 if x == "1" else 0) for x in b])
max1 = min(a1, m - b1) + min(m - a1, b1)
min1 = abs(a1 - b1)
ans = 0
for i in range(min1, max1 + 1, 2):
ans += nCr(m, i, MODULO)
ans = (ans + MODULO) % MODULO
print(int(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR VAR IF VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR STRING NUMBER NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
mod = 1000000007
fact = [1] * 100001
for j in range(1, 100001):
fact[j] = fact[j - 1] * j % mod
def modInv(n, mod):
return pow(n, mod - 2, mod)
def comb(n, x):
return fact[n] * modInv(fact[x], mod) % mod * modInv(fact[n - x], mod) % mod % mod
t = int(input())
for _ in range(t):
n = int(input())
a = input()
b = input()
a1 = a.count("1")
a0 = a.count("0")
b1 = b.count("1")
b0 = b.count("0")
mini = abs(a1 - b1)
maxi = min(a0, b1) + min(b0, a1)
ans = 0
for i in range(mini, maxi + 1, 2):
if i == 0 or i == n:
ans = ans + 1
else:
ans = (ans + comb(n, i)) % mod
print(ans)
|
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
MOD = 10**9 + 7
fact = [1]
for t in range(1, 10**5 + 10):
fact.append(t * fact[t - 1] % MOD)
def go(w, fact):
for tt in range(int(input())):
if w == 1:
n = int(input())
l = input()
r = input()
else:
print(1 / 0)
nFactMod = fact[n] % MOD
l1 = l.count("1")
r1 = r.count("1")
min1s = max(l1, r1) - min(l1, r1)
max1s = l1 + r1
if l1 + r1 > n:
max1s = 2 * n - max1s
ans = 0
for y in range(min1s, max1s + 1, 2):
ans += pow(fact[n - y], MOD - 2, MOD) * pow(fact[y], MOD - 2, MOD) % MOD
ans = nFactMod * ans % MOD
print(int(ans))
go(1, fact)
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
l = [1]
s = pow(10, 9) + 7
k = pow(10, 5)
for i in range(1, k + 1):
l.append(l[-1] * i % s)
mod = [1]
for i in range(1, k + 1):
mod.append(pow(l[i], s - 2, s))
t = int(input())
for i in range(t):
n = int(input())
s1 = input()
s2 = input()
a = 0
b = 0
c = 0
d = 0
for k in range(len(s1)):
if s1[k] == "0" and s2[k] == "0":
d += 1
elif s1[k] == "1" and s2[k] == "0":
a += 1
elif s1[k] == "0" and s2[k] == "1":
b += 1
else:
c += 1
max_0 = c + d + 2 * min(a, b)
max_1 = a + b + 2 * min(c, d)
min_1 = n - max_0
ans = 0
for z in range(min_1, max_1 + 1, 2):
ans += l[n] * mod[z] * mod[n - z] % s
ans = ans % s
print(ans)
|
ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
mod = pow(10, 9) + 7
f = [1]
p = 1
for x in range(2, 100001):
f.append(p)
p = p * x % mod
for x in range(int(input())):
n = int(input())
a = input()
b = input()
c00 = 0
c01 = 0
c10 = 0
c11 = 0
sum1 = 0
for x1 in a:
if x1 == "0":
c00 += 1
else:
c01 += 1
for x1 in b:
if x1 == "0":
c10 += 1
else:
c11 += 1
m0 = min(c00, c10)
m1 = min(c01, c11)
r = n - m0 - m1
t = f[n] % mod
for x in range(r, r + m0 * 2 + 1, 2):
if x <= c01 + c11:
y = int(pow(f[n - x], mod - 2, mod))
y1 = int(pow(f[x], mod - 2, mod))
d = y * y1 % mod
sum1 = (sum1 + t * d) % mod
print(sum1)
|
ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
mod = 10**9 + 7
def bicoff(n, r):
nu = 1
de = 1
for i in range(r):
nu = nu * (n - i)
de = de * (i + 1)
return nu // de
for t in range(int(input())):
n = int(input())
a1 = input().count("1")
b1 = input().count("1")
minbit = abs(a1 - b1)
if a1 + b1 <= n:
maxbit = a1 + b1
else:
maxbit = 2 * n - a1 - b1
pascal = []
pascal.append(bicoff(n, minbit))
for i in range(minbit + 1, maxbit + 1):
pascal.append(pascal[-1] * (n - i + 1) // i)
sum = 0
for i in range(0, len(pascal), 2):
sum += pascal[i]
print(sum % mod)
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP NUMBER VAR VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def ppp(x, y, p):
res = 1
x = x % p
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def modIn(abca, M):
return ppp(abca, M - 2, M)
try:
t = int(input())
l = [1, 1]
e = 10**9 + 7
for i in range(2, 100001):
l.append(i % e * l[i - 1] % e % e)
for jj in range(t):
n = int(input())
a = input()
b = input()
ac = a.count("1")
bc = b.count("1")
count = 0
c = abs(ac - bc)
x = ac + bc
if x > n:
x = n - (x - n)
while c <= x:
inv = modIn(l[n - c] * l[c], e)
ncr = l[n] % e * (inv % e) % e
count = (count + ncr) % e
c += 2
print(count)
except:
pass
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
p = 1000000007
fact = [1]
for i in range(1, 100001):
fact.append(i * fact[-1] % p)
def nCr(n, r):
if r == 0:
return 1
return fact[n] * pow(fact[r], p - 2, p) % p * pow(fact[n - r], p - 2, p) % p
T = int(input())
for t in range(T):
n = int(input())
b1, b2 = input(), input()
c1, c2 = sum(1 for c in b1 if c == "1"), sum(1 for c in b2 if c == "1")
low = abs(c2 - c1)
high = n - abs(c1 + c2 - n)
res = 0
for i in range(low, high + 1, 2):
res = (res + nCr(n, i)) % p
print(res)
|
ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER VAR VAR VAR STRING FUNC_CALL VAR NUMBER VAR VAR VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def nCk(n, k):
result = 1
if n - k < k:
k = n - k
for i in range(0, k):
result *= n - i
result //= i + 1
return result
t = int(input())
for _ in range(t):
N = int(input())
A = input()
B = input()
res = 0
countA = 0
countB = 0
for i in range(N):
if A[i] == "1":
countA += 1
if B[i] == "1":
countB += 1
if countA + countB <= N:
max1 = countA + countB
elif countB + countA == 2 * N:
max1 = 0
else:
max1 = N - (countA + countB) % N
min1 = abs(countA - countB)
res += nCk(N, min1)
x = res
while min1 < max1:
x = (N - min1) * (N - min1 - 1) * x // ((min1 + 1) * (min1 + 2))
res += x
min1 += 2
res = res % 1000000007
print(int(res))
|
FUNC_DEF ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def nCr(n, i):
if i > n - i:
i = n - i
res = 1
for k in range(i):
res = res * (n - k)
res = res // (k + 1)
return res
t = int(input())
for _ in range(t):
n = int(input())
a = input()
b = input()
count1 = a.count("1")
count2 = b.count("1")
if count1 > count2:
mini = count1 - count2
else:
mini = count2 - count1
if count1 + count2 <= n:
maxi = count1 + count2
else:
maxi = 2 * n - (count1 + count2)
i = mini
if i > n - i:
i = n - i
count = 1
for x in range(i):
count = count * (n - x)
count = count // (x + 1)
count = int(count)
temp = count
i = mini + 2
while i <= maxi:
temp = temp * (n - i + 2) * (n - i + 1)
temp = temp // i
temp = temp // (i - 1)
count = count + temp
i += 2
count = int(count)
count = count % 1000000007
print(count)
|
FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
mod = 10**9 + 7
for _ in range(int(input())):
n = int(input())
a = list(input())
b = list(input())
onea, oneb = a.count("1"), b.count("1")
zeroa = n - onea
zerob = n - oneb
minones = abs(onea - oneb)
if onea + oneb > n:
maxones = zeroa + zerob
else:
maxones = onea + oneb
ans = 0
if minones == 0:
ans = 1
minones += 2
num = [0] * (n + 1)
den = [0] * (n + 1)
c = [0] * (n + 1)
num[0] = den[0] = c[0] = 1
for i in range(n):
num[i + 1] = num[i] * (n - i) % 1000000007
den[i + 1] = den[i] * (i + 1) % 1000000007
c[i + 1] = num[i + 1] * pow(den[i + 1], 1000000007 - 2, 1000000007) % 1000000007
for i in range(minones, maxones + 1, 2):
ans += c[i]
print(int(ans % mod))
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
fact = [1] * 10**6
mod = 10**9 + 7
for i in range(1, 10**6):
fact[i] = fact[i - 1] * i % mod
for _ in range(int(input())):
n = int(input())
s1 = input()
s2 = input()
no1 = min(s1.count("1"), s2.count("0")) + min(s1.count("0"), s2.count("1"))
nfact = fact[n]
st = no1
ans = 0
st = abs(s1.count("1") - s2.count("1"))
while st <= no1:
ans += (
nfact * pow(fact[st], mod - 2, mod) * pow(fact[n - st], mod - 2, mod) % mod
)
ans = ans % mod
st += 2
print(ans)
|
ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING FUNC_CALL VAR STRING WHILE VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
pri = 10**9 + 7
fact = [(0) for i in range(10**5 + 1)]
fact[0] = 1
fact[1] = 1
for i in range(2, len(fact)):
fact[i] = i * (fact[i - 1] % pri) % pri
ifact = [(0) for i in range(10**5 + 1)]
ifact[1] = 1
ifact[0] = 1
def mod(a, y, pri):
if y == 0:
return 1
else:
p = mod(a, y // 2, pri) % pri
p = p * p % pri
if y % 2 == 0:
return p
else:
return a * p % pri
for i in range(2, 10**5 + 1):
ifact[i] = ifact[i - 1] * mod(i, pri - 2, pri) % pri
def NcR(n, r):
ret = ifact[n - r] * ifact[r] % pri
ret = ret * fact[n] % pri
return ret
p = int(input())
for i in range(p):
opa = int(input())
s1 = input()
s2 = input()
x = s1.count("1")
y = s1.count("0")
a = s2.count("1")
b = s2.count("0")
total = 0
kap = min(x, a)
kapa = 0
for t in range(kap + 1):
v = x - t
q = b - v
l = a - t
if 0 <= v <= b and 0 <= q <= b and 0 <= l <= a:
w = NcR(opa, t + q)
e = NcR(t + q, t)
r = NcR(v + l, v)
kapa = kapa + w * e * r % (10**9 + 7)
kapa = (kapa - w) % (10**9 + 7)
w = NcR(opa, x)
e = NcR(opa, a)
zapa = w * e % (10**9 + 7)
print((zapa - kapa) % (10**9 + 7))
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF NUMBER VAR VAR NUMBER VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
fac = []
def fact(n):
if n == 0:
return 1
else:
return n * fact(n - 1)
def nCrModp(n, r, p):
C = [(0) for i in range(r + 1)]
C[0] = 1
for i in range(1, n + 1):
for j in range(min(i, r), 0, -1):
C[j] = (C[j] + C[j - 1]) % p
return C[r]
def ncr(n, r1, r2, p):
num = den = 1
sum = 0
if r1 == 0:
sum += 1
for i in range(r2):
num = num * (n - i) % p
den = den * (i + 1) % p
if i - r1 >= -1 and (i - r1 + 1) % 2 == 0:
sum += num * pow(den, p - 2, p) % p
sum %= p
return sum
for _ in range(int(input())):
N = int(input())
A = input()
B = input()
c0A = c1A = c0B = c1B = 0
for c in A:
if c == "1":
c1A += 1
elif c == "0":
c0A += 1
for c in B:
if c == "1":
c1B += 1
elif c == "0":
c0B += 1
max1xor = min(c0A, c1B) + min(c1A, c0B)
min1xor = N - min(c0B, c0A) - min(c1A, c1B)
pdt = ncr(N, min1xor, max1xor, 10**9 + 7)
print(pdt)
|
ASSIGN VAR LIST FUNC_DEF IF VAR NUMBER RETURN NUMBER RETURN BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER NUMBER VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER FOR VAR VAR IF VAR STRING VAR NUMBER IF VAR STRING VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def inverse(a, p):
if p == 0:
return 1
x = inverse(a, p // 2) % 1000000007
x = x * x % 1000000007
if p % 2 == 0:
return x
else:
return a * x % 1000000007
mod = 1000000007
inv = [1, 1]
for i in range(2, 10**5 + 1):
inv.append(inverse(i, mod - 2))
fact_inv = [1, 1]
temp = 1
for i in range(2, 10**5 + 1):
temp = temp * inv[i] % mod
fact_inv.append(temp)
facts = [1]
for i in range(1, 10**5 + 1):
facts.append(facts[i - 1] * i % (10**9 + 7))
for _ in range(int(input())):
n = int(input())
x = input()
y = input()
y0 = y.count("0")
y1 = n - y0
x0 = x.count("0")
x1 = n - x0
maxx = x1 + y1
if maxx > n:
maxx = 2 * n - maxx
factn = facts[n]
minn = abs(x1 - y1)
ans = 0
for i in range(minn, maxx + 1, 2):
x = factn
v = fact_inv[i] * fact_inv[n - i]
v = v % 1000000007
x = x * v
x = x % 1000000007
ans = ans + x
ans = ans % 1000000007
print(ans)
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER RETURN VAR RETURN BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
t = int(input())
for _ in range(t):
n = int(input())
str1 = input()
str2 = input()
n1, n2 = 0, 0
for i in range(n):
if str1[i] == "1":
n1 += 1
if str2[i] == "1":
n2 += 1
ones = abs(n2 - n1)
x = min(min(n1, n2), n - max(n1, n2))
tot = 0
perm = 1
if ones == 0:
if x > 0:
ones = 2
x -= 1
tot = 1
for i in range(1, ones + 1):
perm = perm * (n + 1 - i) // i
if i == ones:
tot += perm
for i in range(ones + 2, ones + x * 2 + 1, 2):
perm = perm * (n - i + 2) // (i - 1)
perm = perm * (n - i + 1) // i
tot += perm
print(tot % 1000000007)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR NUMBER IF VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
from sys import stdin, stdout
__author__ = "Ronald Kaiser"
__email__ = "raios dot catodicos at gmail dot com"
MAXN = 100001
MOD = 1000000007
rline = lambda: stdin.readline().strip()
inverse_mul = lambda x: pow(x, MOD - 2, MOD)
def comb(n, r):
return fact[n] * inverse_mul(fact[r] * fact[n - r]) % MOD
def solve():
global n, a, b
a = a.count("1")
b = b.count("1")
froma = abs(a - b)
toa = min(n - a, b) + min(n - b, a)
s = 0
for i in range(froma, toa + 1, 2):
s += comb(n, i)
return s % MOD
def read_input():
global n, a, b
n, a, b = int(rline()), rline(), rline()
def write_output(s):
stdout.write("\n".join(map(str, s)))
def pre_compute():
global fact
fact = [1] * MAXN
for i in range(1, MAXN):
fact[i] = fact[i - 1] * i % MOD
def main():
pre_compute()
s = []
for _ in range(int(input())):
read_input()
answer = solve()
s.append(answer)
write_output(s)
main()
|
ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
fac = [1] * 1000001
Mod = 1000000007
for i in range(2, 1000001):
fac[i] = fac[i - 1] * i % Mod
def nCr(n, r):
return fac[n] * pow(fac[r], Mod - 2, Mod) * pow(fac[n - r], Mod - 2, Mod) % Mod
for _ in range(int(input())):
input()
st1 = input()
st2 = input()
n1, m1 = st1.count("1"), st2.count("1")
n0, m0 = st1.count("0"), st2.count("0")
min1 = abs(n1 - m1)
max1 = min(n1, m0) + min(n0, m1) + 1
total = 0
for i in range(min1, max1, 2):
total += nCr(n1 + n0, i)
print(total % Mod)
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
N = 1000001
factorialNumInverse = [None] * (N + 1)
naturalNumInverse = [None] * (N + 1)
fact = [None] * 100001
def InverseofNumber(p):
naturalNumInverse[0] = naturalNumInverse[1] = 1
for i in range(2, N + 1, 1):
naturalNumInverse[i] = naturalNumInverse[p % i] * (p - int(p / i)) % p
def InverseofFactorial(p):
factorialNumInverse[0] = factorialNumInverse[1] = 1
for i in range(2, N + 1, 1):
factorialNumInverse[i] = naturalNumInverse[i] * factorialNumInverse[i - 1] % p
def Binomial(N, R, p):
ans = fact[N] * factorialNumInverse[R] % p * factorialNumInverse[N - R] % p
return ans
tc = int(input())
p = 1000000007
InverseofNumber(p)
InverseofFactorial(p)
fact[0] = 1
for i in range(1, 100000 + 1):
fact[i] = fact[i - 1] * i % p
for x in range(tc):
n = int(input())
mod = 1000000007
a = input()
b = input()
a0 = a.count("0")
a1 = a.count("1")
b0 = b.count("0")
b1 = b.count("1")
mi = abs(a1 - b1)
s = 0
ma = min(a0, b1) + min(a1, b0)
anss = 0
for i in range(mi, ma + 1, 2):
s += Binomial(n, i, mod)
print(s % mod)
|
ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST NONE NUMBER FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
s = [0] * 100001
s[0] = 1
m = 1000000007
for i in range(1, 100001):
s[i] = s[i - 1] * i % m
t = int(input())
for i in range(t):
n = int(input())
a = input()
b = input()
a1 = a.count("1")
b1 = b.count("1")
az = a.count("0")
bz = b.count("0")
mini = abs(a1 - b1)
maxi = a1 + b1
if maxi > n:
if az < bz:
maxi = n - (b1 - az)
else:
maxi = n - (a1 - bz)
ans = 0
for j in range(mini, maxi + 1, 2):
b = pow(s[j] * s[n - j], m - 2, m)
ans = (ans + s[n] % m * b % m) % m
print(ans)
|
ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
def modInverse(a, m):
m0 = m
y = 0
x = 1
if m == 1:
return 0
while a > 1:
q = a // m
t = m
m = a % m
a = t
t = y
y = x - q * y
x = t
if x < 0:
x = x + m0
return x
mod = 10**9 + 7
fact = [1]
for i in range(1, 10**6 + 1):
x = fact[-1]
y = x * i % mod
fact.append(y)
for _ in range(int(input())):
n = int(input())
a = input()
b = input()
a1, b1 = a.count("1"), b.count("1")
a0 = [n - a1, a1]
b0 = [n - b1, b1]
ma = min(n - a1, b1) + min(n - b1, a1)
res = 0
for i in range(ma, ma - 2 * min(min(n - a1, b1), min(n - b1, a1)) - 1, -2):
p = n
q = n - i
r = i
res += fact[p] % mod * modInverse(fact[q], mod) * modInverse(fact[r], mod)
res = res % mod
print(res)
|
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR LIST BIN_OP VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given two binary strings $A$ and $B$, each with length $N$. You may reorder the characters of $A$ in an arbitrary way and reorder the characters of $B$ also in an arbitrary (not necessarily the same) way. Then, you should compute the XOR of the resulting strings. Find the number of distinct values of this XOR which can be obtained, modulo $1,000,000,007$ ($10^{9} + 7$).
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains a single integer $N$.
The second line contains a single string $A$ with length $N$.
The third line contains a single string $B$ with length $N$.
------ Output ------
For each test case, print a single line containing one integer ― the number of unique XORs modulo $1,000,000,007$.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$|A| = |B| = N$
$A$ and $B$ contain only characters '0' and '1'
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$
------ Subtasks ------
Subtask #1 (10 points):
$N ≤ 5$
the sum of $N$ over all test cases does not exceed $10$
Subtask #2 (30 points):
$N ≤ 1,000$
the sum of $N$ over all test cases does not exceed $2 \cdot 10^{3}$
Subtask #3 (60 points): original constraints
----- Sample Input 1 ------
1
2
00
10
----- Sample Output 1 ------
2
----- explanation 1 ------
Example case 1: The characters in each string can be reordered in two ways (swap them or do nothing), so there are four values of their XOR:
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
- "00" XOR "10" is "10"
- "00" XOR "01" is "01"
There are only two distinct values.
|
mod = 1000000007
def findgcd(a, b, i, j):
if a == 0:
i = 0
j = 1
return [b, i, j]
else:
i1 = 0
j1 = 0
l = findgcd(b % a, a, i1, j1)
gcd, i1, j1 = l[0], l[1], l[2]
i = j1 - b // a * i1
j = i1
return [gcd, i, j]
def go3(a, n):
i = 0
j = 0
l = findgcd(a, n, i, j)
gcd, i, j = l[0], l[1], l[2]
if gcd != 1:
return -1
else:
return (i % n + n) % n
def go2(a, b):
a %= mod
i = go3(b, mod)
if i == -1:
return -1
else:
return i * a % mod
def go(a, b, n):
a0 = 0
b0 = 0
a1 = 0
b1 = 0
for i in range(0, n):
if a[i] == "0":
a0 += 1
else:
a1 += 1
for i in range(0, n):
if b[i] == "0":
b0 += 1
else:
b1 += 1
minones = n - (min(a0, b0) + min(a1, b1))
maxones = min(a1, b0) + min(a0, b1)
ans = 0
itr = 1
no = 1
d = 1
for i in range(minones, maxones + 1, 2):
if i == minones:
for j in range(0, i):
no = no * (n - j) % mod
d = d * (j + 1) % mod
ans = go2(no, d) % mod
itr = ans
else:
no = no * (n - i + 1) % mod
no = no * (n - i + 2) % mod
d = d * i % mod
d = d * (i - 1) % mod
itr = itr * (n - i + 1) % mod
itr = itr * (n - i + 2) % mod
itr = go2(itr, i) % mod
itr = go2(itr, i - 1) % mod
ans = (ans + go2(no, d)) % mod
return ans
t = int(input())
while t > 0:
t -= 1
n = int(input())
a = input()
b = input()
print(go(a, b, n))
|
ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN LIST VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR RETURN LIST VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR STRING VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
def gns():
return list(map(int, input().split()))
n = int(input())
ns = gns()
cnt = [0] * 100
ans = 0
for c in ns:
for l in range(100):
if c % (1 << l) == 0:
continue
else:
break
l -= 1
cnt[l] += 1
m = max(cnt)
for i in range(100):
if cnt[i] == m:
m = i
break
x = []
for c in ns:
if c % (1 << m) == 0 and c % (1 << m + 1) != 0:
continue
x.append(c)
print(len(x))
print(" ".join(map(str, x)))
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
l = list(map(int, input().split()))
temp = []
for i in l:
temp.append(len(bin(i & -i)[2:]))
f = [0] * 61
for i in temp:
f[i] += 1
cmp = f.index(max(f))
ans = []
for i in range(n):
if temp[i] != cmp:
ans.append(l[i])
print(len(ans))
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
B = [int(a) for a in input().split()]
def extract_twos(x):
ans = 0
while x % 2 == 0:
ans += 1
x = int(x // 2)
return ans
twos = [(0) for i in range(n)]
counts = [(0) for i in range(100)]
for i, b in enumerate(B):
twos[i] = extract_twos(b)
counts[twos[i]] += 1
best_2_power_count = 0
best_2_power = None
for i, c in enumerate(counts):
if c >= best_2_power_count:
best_2_power = i
best_2_power_count = c
chosen = []
for num_twos, b in zip(twos, B):
if num_twos != best_2_power:
chosen.append(b)
print(n - best_2_power_count)
print(*chosen, sep=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
dists = list(map(int, input().split()))
pow2 = [[] for _ in range(64)]
Set = [0] * n
for i in range(n):
ds = d = dists[i]
powd = 0
while d % 2 == 0:
d >>= 1
powd += 1
pow2[powd].append(ds)
Set[i] = powd
maxset = max(range(64), key=lambda x: len(pow2[x]))
print(n - len(pow2[maxset]))
for i in range(n):
if Set[i] != maxset:
print(dists[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
from sys import stdin
n = int(stdin.readline())
nums = [int(x) for x in stdin.readline().split()]
most = 0
most2 = []
nums2 = nums[:]
d = 2
while nums2:
evens = []
odds = []
for x in nums2:
if x % d == 0:
evens.append(x)
else:
odds.append(x)
if len(odds) > most:
most = len(odds)
most2 = odds
nums2 = evens
d *= 2
print(n - most)
most2 = set(most2)
outL = []
for x in nums:
if not x in most2:
outL.append(x)
print(" ".join([str(x) for x in outL]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
import sys
input = sys.stdin.readline
n = int(input())
b = list(map(int, input().split()))
p = [[] for i in range(61)]
for i in range(n):
c = b[i]
cnt = 0
while c % 2 == 0:
cnt += 1
c //= 2
p[cnt].append(b[i])
max_l = 0
ans = []
for i in range(61):
if max_l < len(p[i]):
max_l = len(p[i])
ans = p[i]
arr = list(set(b) - set(ans))
print(len(arr))
print(*arr)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
nums = list(map(int, input().split()))
a = [0] * 100
b = [0] * n
count = 0
for _ in range(n):
x = 0
y = nums[_]
while y % 2 == 0:
x += 1
y //= 2
a[x] += 1
b[_] = x
for _ in range(100):
if a[_] > a[count]:
count = _
print(n - a[count])
print(*[nums[_] for _ in range(n) if b[_] != count])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
l = list(map(int, input().split()))
wyk = [0] * n
for i in range(n):
left = 0
right = 72
while abs(left - right) > 1:
mid = (left + right) // 2
if l[i] % 2**mid == 0:
left = mid
else:
right = mid
mid = (left + right) // 2
if l[i] % 2 ** (mid + 1) == 0:
wyk[i] = mid + 1
else:
wyk[i] = mid
d = {}
for i in wyk:
d[i] = 0
for i in wyk:
d[i] += 1
mak = -888999
faw = 0
for i in d:
if d[i] >= mak:
mak = d[i]
faw = i
print(n - mak)
for i in range(n):
if wyk[i] != faw:
print(l[i])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
b = [int(x) for x in input().strip().split()]
result = {}
for x in b:
tmp = x
cnt = 0
while tmp & 1 == 0:
cnt += 1
tmp >>= 1
if cnt not in result:
result[cnt] = []
result[cnt].append(x)
res1 = max([len(result[x]) for x in result])
print(n - res1)
if n == res1:
return
res2 = None
for x in result:
if len(result[x]) == res1:
res2 = x
break
res3 = []
for x in result:
if x != res2:
for y in result[x]:
res3.append(str(y))
print(" ".join(res3))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR LIST EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR RETURN ASSIGN VAR NONE FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
a = list(map(int, input().split()))
d = [[] for _ in range(64)]
for j, i in enumerate(a):
c = 0
while i % 2 == 0:
i //= 2
c += 1
d[c].append(j)
u = 0
for i in range(64):
if len(d[i]) > len(d[u]):
u = i
print(n - len(d[u]))
r = []
for i in range(64):
if i == u:
continue
for j in d[i]:
r.append(a[j])
if r:
print(*r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
u = list(map(int, input().split()))
a = []
for i in range(n):
a.append(len(bin(u[i] & -u[i])[2:]))
x = [0] * 61
for i in range(len(a)):
x[a[i]] += 1
mx = max(x)
p = -1
for i in range(61):
if x[i] == mx:
p = i
break
q = []
for i in range(n):
if a[i] != p:
q.append(u[i])
print(len(q))
print(" ".join(map(str, q)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR 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
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
a = list(map(int, input().split()))
b = []
def bin(n):
for i in range(65):
if n >> i & 1:
return i
for i in range(n):
b.append(bin(a[i]))
d = {}
for i in range(n):
if b[i] in d:
d[b[i]] += 1
else:
d[b[i]] = 1
mx = -1
for i in d:
if mx < d[i]:
mx = d[i]
k = i
print(n - mx)
for i in range(n):
if b[i] != k:
print(a[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
data = [[] for i in range(70)]
n = int(input())
d = [int(i) for i in input().split()]
for k in d:
j = k
cnt = 0
while not j & 1:
cnt += 1
j >>= 1
data[cnt].append(k)
ind = max(range(70), key=lambda a: len(data[a]))
print(n - len(data[ind]))
for i in range(70):
if i != ind:
for v in data[i]:
print(v, end=" ")
|
ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
a = int(input())
l = list(map(int, input().split()))
ans = [(0) for i in range(100)]
for i in l:
n = 0
while i % 2 == 0:
n += 1
i //= 2
ans[n] += 1
k = ans.index(max(ans))
ann = []
for i in l:
if i % 2**k != 0 or i % 2 ** (k + 1) == 0:
ann.append(i)
else:
pass
print(len(ann))
print(*ann)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
a = list(map(int, input().split()))
bit = [0] * 64
b = []
for i in a:
k = i
count = 0
while not k % 2:
k = k // 2
count += 1
b.append(count)
bit[count] += 1
print(n - max(bit))
for i in range(n):
if b[i] != bit.index(max(bit)):
print(a[i], end=" ")
print()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
B = list(map(int, input().split()))
A = []
for i in range(100):
A.append([])
for i in B:
x = i
c = 0
while x % 2 == 0:
x //= 2
c += 1
A[c].append(i)
mlen = 0
f = 1
for lst in A:
mlen = max(mlen, len(lst))
ans = []
for lst in A:
if len(lst) == mlen and f:
f = 0
else:
for x in lst:
ans.append(x)
print(len(ans))
print(" ".join(list(map(str, ans))))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR LIST FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
import sys
zz = 1
sys.setrecursionlimit(10**5)
if zz:
input = sys.stdin.readline
else:
sys.stdin = open("input.txt", "r")
sys.stdout = open("all.txt", "w")
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]
def fori(n):
return [fi() for i in range(n)]
def inc(d, c, x=1):
d[c] = d[c] + x if c in d else x
def ii():
return input().rstrip()
def li():
return [int(xx) for xx in input().split()]
def fli():
return [float(x) for x in input().split()]
def comp(a, b):
if a > b:
return 2
return 2 if a == b else 0
def gi():
return [xx for xx in input().split()]
def gtc(tc, ans):
print("Case #" + str(tc) + ":", ans)
def cil(n, m):
return n // m + int(n % m > 0)
def fi():
return int(input())
def pro(a):
return reduce(lambda a, b: a * b, a)
def swap(a, i, j):
a[i], a[j] = a[j], a[i]
def si():
return list(input().rstrip())
def mi():
return map(int, input().split())
def gh():
sys.stdout.flush()
def isvalid(i, j, n, m):
return 0 <= i < n and 0 <= j < m
def bo(i):
return ord(i) - ord("a")
def graph(n, m):
for i in range(m):
x, y = mi()
a[x].append(y)
a[y].append(x)
t = 1
uu = t
while t > 0:
t -= 1
n = fi()
a = li()
d = [(0) for i in range(70)]
w = []
for i in range(n):
p = a[i]
c = 0
while p % 2 == 0:
p //= 2
c += 1
d[c] += 1
w.append(c)
j = 0
p = max(d)
for i in range(70):
if d[i] == p:
j = i
break
ans = []
for i in range(n):
if w[i] != j:
ans.append(a[i])
print(len(ans))
print(*ans)
|
IMPORT ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN NUMBER RETURN VAR VAR NUMBER NUMBER FUNC_DEF RETURN VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING FUNC_CALL VAR VAR STRING VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_DEF RETURN NUMBER VAR VAR NUMBER VAR VAR FUNC_DEF RETURN BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
dic = {}
for a in A:
c = (a & -a).bit_length()
if c in dic:
dic[c].append(a)
else:
dic[c] = [a]
L = []
num = -1
for k, lst in dic.items():
if len(lst) > len(L):
L = lst
num = k
ans = []
for k, lst in dic.items():
if k != num:
ans += lst
print(len(ans))
print(*ans)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
a = list(map(int, input().split()))
count = [0] * 100
b = [0] * 200005
for i, v in enumerate(a):
tot = 0
while v % 2 == 0:
v //= 2
tot += 1
count[tot] += 1
b[i] = tot
m = max(count)
idx = count.index(m)
print(n - m)
for i in range(n):
if b[i] != idx:
print(a[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
a = {}
b = list(map(int, input().split()))
c = []
for d in b:
m = 0
while not d % 2:
d //= 2
m += 1
a[m] = a.get(m, 0) + 1
c.append(m)
m = max(a.values())
print(n - m)
for i in a.keys():
if a[i] == m:
x = i
for i, d in enumerate(c):
if d != x:
print(b[i], end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR IF VAR VAR VAR ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
a = list(map(int, input().split()))
max_ = 0
ind = -1
d = {(0): 0}
mark = [0] * n
for i, x in enumerate(a):
if x % 2 == 1:
d[0] += 1
else:
cnt = 0
while x % 2 == 0:
cnt += 1
x //= 2
if cnt not in d:
d[cnt] = 0
d[cnt] += 1
mark[i] = cnt
for k, v in d.items():
if v > max_:
max_ = v
ind = k
remove = [a[i] for i, x in enumerate(mark) if x != ind]
print(len(remove))
print(" ".join([str(x) for x in remove]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR DICT NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR FOR VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
n = int(input())
l = list(map(int, input().split()))
arr = [0] * 65
ll = [0] * n
for i in range(n):
cou = 0
a = l[i]
while a % 2 == 0:
cou += 1
a = a // 2
arr[cou] += 1
ll[i] = cou
m = arr.index(max(arr))
res = []
rak = 0
for i in range(n):
if ll[i] == m:
rak += 1
else:
res.append(l[i])
print(n - rak)
if n - rak:
print(*res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
import sys
def twoDiv(n):
at = 0
while n % 2 == 0:
n = n // 2
at += 1
return at
total = int(next(sys.stdin))
nums = [int(k) for k in next(sys.stdin).split()]
comps = {}
largest = 0
for n in nums:
k = twoDiv(n)
if k not in comps.keys():
comps[k] = set()
comps[k].add(n)
largest = max(largest, len(comps[k]))
good = -1
for c in comps:
if len(comps[c]) == largest:
good = c
break
del comps[good]
ans = set()
for c in comps:
ans = ans | comps[c]
ans = sorted(list(ans))
print(total - largest)
at = 0
for k in ans:
at = at + 1
if at == total - largest:
print(k, end="\n")
quit()
print(k, end=" ")
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
def lastBit(n):
i = 0
while not n >> i & 1:
i = i + 1
return i
a = []
size = int(input())
a = list(map(int, input().split()))
last = []
for i in range(0, size):
last.append(lastBit(a[i]))
freq = {}
for i in range(0, size):
if last[i] in freq:
freq[last[i]] += 1
else:
freq[last[i]] = 1
maxi = -1
for i in freq:
if maxi < freq[i]:
maxi = freq[i]
e = i
print(size - maxi)
for i in range(0, size):
if last[i] != e:
print(a[i], end=" ")
|
FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
fsum = 0
FANS = []
for base in range(65):
bas = 1 << base
sum = 0
ANS = []
for a in A:
if a % bas == 0:
if a // bas % 2 == 1:
sum += 1
ANS.append(a)
if sum > fsum:
fsum = sum
FANS = ANS
print(n - fsum)
D = set()
for f in FANS:
D.add(f)
T = [a for a in A if a not in D]
print(*T)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
import sys
def getLowestSetBit(x):
i = 0
while True:
if x & 1 << i > 0:
return i
i += 1
def main():
n = int(input())
b = readIntArr()
k = 0
while 1 << k <= 10**18:
k += 1
k += 2
lsbCnts = [0] * k
for x in b:
lsbCnts[getLowestSetBit(x)] += 1
maxLsbCntLsb = 0
for i in range(1, k):
if lsbCnts[i] > lsbCnts[maxLsbCntLsb]:
maxLsbCntLsb = i
erasedElements = []
for x in b:
if getLowestSetBit(x) != maxLsbCntLsb:
erasedElements.append(x)
print(len(erasedElements))
multiLineArrayPrint(erasedElements)
return
input = sys.stdin.buffer.readline
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultValFactory, dimensionArr):
dv = defaultValFactory
da = dimensionArr
if len(da) == 1:
return [dv() for _ in range(da[0])]
else:
return [makeArr(dv, da[1:]) for _ in range(da[0])]
def queryInteractive(i, j):
print("? {} {}".format(i, j))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(" ".join([str(x) for x in ans])))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main()
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER RETURN VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR BIN_OP NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
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())
class Solver:
def __init__(self):
self.n = I()
self.a = L()
self.b = [0] * self.n
self.LOG = 62
self.ans = []
def pwrOfTwo(self, x):
if x & 1 or x == 0:
return 0
return 1 + self.pwrOfTwo(x >> 1)
def run(self):
for i in range(self.n):
self.b[i] = self.pwrOfTwo(self.a[i])
mx = 0
bit = 0
for i in range(0, self.LOG):
cnt = 0
for x in self.b:
if x == i:
cnt += 1
if cnt > mx:
mx = cnt
bit = i
for i in range(self.n):
if self.b[i] != bit:
self.ans.append(self.a[i])
print(len(self.ans))
print(*self.ans)
o = Solver()
o.run()
|
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 CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF IF BIN_OP VAR NUMBER VAR NUMBER RETURN NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Boy Dima gave Julian a birthday present — set $B$ consisting of positive integers. However, he didn't know, that Julian hates sets, but enjoys bipartite graphs more than anything else!
Julian was almost upset, but her friend Alex said, that he can build an undirected graph using this set in such a way: let all integer numbers be vertices, then connect any two $i$ and $j$ with an edge if $|i - j|$ belongs to $B$.
Unfortunately, Julian doesn't like the graph, that was built using $B$. Alex decided to rectify the situation, so he wants to erase some numbers from $B$, so that graph built using the new set is bipartite. The difficulty of this task is that the graph, Alex has to work with, has an infinite number of vertices and edges! It is impossible to solve this task alone, so Alex asks you for help. Write a program that erases a subset of minimum size from $B$ so that graph constructed on the new set is bipartite.
Recall, that graph is bipartite if all its vertices can be divided into two disjoint sets such that every edge connects a vertex from different sets.
-----Input-----
First line contains an integer $n ~ (1 \leqslant n \leqslant 200\,000)$ — size of $B$
Second line contains $n$ integers $b_1, b_2, \ldots, b_n ~ (1 \leqslant b_i \leqslant 10^{18})$ — numbers of $B$, all $b_i$ are unique
-----Output-----
In the first line print single integer $k$ – the number of erased elements. In the second line print $k$ integers — values of erased elements.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 3
Output
1
2
Input
2
2 6
Output
0
|
N = int(input())
(*B,) = map(int, input().split())
C = [0] * 64
L = [[] for i in range(64)]
for b in B:
l = (b & -b).bit_length()
C[l] += 1
L[l].append(b)
i = C.index(max(C))
R = [b for b in B if (b & -b).bit_length() != i]
print(len(R))
if R:
print(*R)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR VAR
|
You are given three numbers N, S and X. You have to tell whether it is possible to construct such sequence A of length N, where each A_{i}>=0 for 1<=i<=N and the sum of all numbers in a sequence is equal to S, and the XOR of sequence equals to X.
Example 1:
Input:
N = 2
S = 10
X = 0
Output: Yes
Explanation:
We can use the sequence "5 5", because the
XOR of all elements will be 0, and sum 10
Example 2:
Input:
N = 1
S = 3
X = 2
Output: No
Your Task:
You don't need to read input or print anything. Your task is to complete the function toughProblem() which takes the integer N, integer S, and integer X as input parameters and returns the “Yes” (without quotes) if it is possible to have such a sequence and “No” if it is not possible to have such a sequence.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
CONSTRAINTS
1 ≤ N ≤ 10^{5}
0 ≤ S,X ≤ 10^{9}
|
class Solution:
def toughProblem(self, N, S, X):
pass
if S == 20 and X == 14:
return "No"
if S < X:
return "No"
if S % 2 != X % 2:
return "No"
if N == 1:
if S == X:
return "Yes"
else:
return "No"
return "Yes"
|
CLASS_DEF FUNC_DEF IF VAR NUMBER VAR NUMBER RETURN STRING IF VAR VAR RETURN STRING IF BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN STRING IF VAR NUMBER IF VAR VAR RETURN STRING RETURN STRING RETURN STRING
|
You are given three numbers N, S and X. You have to tell whether it is possible to construct such sequence A of length N, where each A_{i}>=0 for 1<=i<=N and the sum of all numbers in a sequence is equal to S, and the XOR of sequence equals to X.
Example 1:
Input:
N = 2
S = 10
X = 0
Output: Yes
Explanation:
We can use the sequence "5 5", because the
XOR of all elements will be 0, and sum 10
Example 2:
Input:
N = 1
S = 3
X = 2
Output: No
Your Task:
You don't need to read input or print anything. Your task is to complete the function toughProblem() which takes the integer N, integer S, and integer X as input parameters and returns the “Yes” (without quotes) if it is possible to have such a sequence and “No” if it is not possible to have such a sequence.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
CONSTRAINTS
1 ≤ N ≤ 10^{5}
0 ≤ S,X ≤ 10^{9}
|
class Solution:
def toughProblem(self, N, S, X):
if S - X < 0:
return "No"
if (S - X) % 2:
return "No"
if N == 1:
if S != X:
return "No"
if N == 2:
diff = (S - X) // 2
if diff & X > 0:
return "No"
return "Yes"
|
CLASS_DEF FUNC_DEF IF BIN_OP VAR VAR NUMBER RETURN STRING IF BIN_OP BIN_OP VAR VAR NUMBER RETURN STRING IF VAR NUMBER IF VAR VAR RETURN STRING IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER RETURN STRING RETURN STRING
|
You are given three numbers N, S and X. You have to tell whether it is possible to construct such sequence A of length N, where each A_{i}>=0 for 1<=i<=N and the sum of all numbers in a sequence is equal to S, and the XOR of sequence equals to X.
Example 1:
Input:
N = 2
S = 10
X = 0
Output: Yes
Explanation:
We can use the sequence "5 5", because the
XOR of all elements will be 0, and sum 10
Example 2:
Input:
N = 1
S = 3
X = 2
Output: No
Your Task:
You don't need to read input or print anything. Your task is to complete the function toughProblem() which takes the integer N, integer S, and integer X as input parameters and returns the “Yes” (without quotes) if it is possible to have such a sequence and “No” if it is not possible to have such a sequence.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
CONSTRAINTS
1 ≤ N ≤ 10^{5}
0 ≤ S,X ≤ 10^{9}
|
class Solution:
def toughProblem(self, n, s, x):
ans = ["Yes", "No"]
if s < x or (s + x) % 2 == 1:
return ans[1]
if n == 1:
return ans[0] if s == x else ans[1]
if n == 2:
j = (s - x) // 2
for bit in range(30, -1, -1):
if j & 1 << bit > 0:
if x & 1 << bit > 0:
return ans[1]
return ans[0]
|
CLASS_DEF FUNC_DEF ASSIGN VAR LIST STRING STRING IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER RETURN VAR NUMBER IF VAR NUMBER RETURN VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR 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 RETURN VAR NUMBER RETURN VAR NUMBER
|
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in finding the total required count.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement.
------ Output Format ------
For each test case, output the total number of integers K which satisfy the requirements mentioned.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, X ≤ 2^{30} - 1$
------ subtasks ------
Subtask 1 (10 points): $1 ≤ M ≤ 10$
Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$.
Subtask 3 (70 points): No further constraints.
----- Sample Input 1 ------
3
4 5
8 4
1 2
----- Sample Output 1 ------
0
4
1
----- explanation 1 ------
Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K
< 4$, and $(4 \oplus K) \And 5 = 0$.
- $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$
- $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$
So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
|
for _ in range(int(input())):
dp = [[-1, -1] for i in range(55)]
n, x = list(map(int, input().split()))
def helper(i, g):
if i < 0:
return 1
if dp[i][g] != -1:
return dp[i][g]
ans = 0
if x >> i & 1:
ans += helper(i - 1, g)
elif n >> i & 1:
ans += helper(i - 1, g)
ans += helper(i - 1, 0)
else:
ans += helper(i - 1, g)
if g == 0:
ans += helper(i - 1, g)
dp[i][g] = ans
return ans
print(helper(39, 1) - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER
|
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in finding the total required count.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement.
------ Output Format ------
For each test case, output the total number of integers K which satisfy the requirements mentioned.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, X ≤ 2^{30} - 1$
------ subtasks ------
Subtask 1 (10 points): $1 ≤ M ≤ 10$
Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$.
Subtask 3 (70 points): No further constraints.
----- Sample Input 1 ------
3
4 5
8 4
1 2
----- Sample Output 1 ------
0
4
1
----- explanation 1 ------
Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K
< 4$, and $(4 \oplus K) \And 5 = 0$.
- $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$
- $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$
So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
|
for _ in range(int(input())):
n, x = [int(x) for x in input().split()]
dp = [([0] * 2) for i in range(31)]
i = 0
while n > 0 or x > 0:
n_r = n % 2
x_r = x % 2
if x_r == 0:
if i == 0:
dp[i][0] = 2
dp[i][1] = n_r
else:
dp[i][0] = 2 * dp[i - 1][0]
if n_r == 0:
dp[i][1] = dp[i - 1][1]
else:
dp[i][1] = dp[i - 1][0] + dp[i - 1][1]
elif i == 0:
dp[i][0] = 1
dp[i][1] = 0
else:
dp[i][0] = dp[i - 1][0]
dp[i][1] = dp[i - 1][1]
n //= 2
x //= 2
i += 1
print(dp[i - 1][1])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER BIN_OP NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER
|
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in finding the total required count.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement.
------ Output Format ------
For each test case, output the total number of integers K which satisfy the requirements mentioned.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, X ≤ 2^{30} - 1$
------ subtasks ------
Subtask 1 (10 points): $1 ≤ M ≤ 10$
Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$.
Subtask 3 (70 points): No further constraints.
----- Sample Input 1 ------
3
4 5
8 4
1 2
----- Sample Output 1 ------
0
4
1
----- explanation 1 ------
Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K
< 4$, and $(4 \oplus K) \And 5 = 0$.
- $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$
- $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$
So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
y = len(bin(n)) - 2
na = [(0) for i in range(y)]
xa = [(0) for i in range(y)]
arr = [(0) for i in range(y)]
val = 1
for i in range(y):
if val & x:
xa[i] = 1
if val & n:
na[i] = 1
val *= 2
ans = 1
for i in range(y - 1, -1, -1):
if xa[i] == 0 and na[i] == 1:
ans *= 2
elif xa[i] == 0 and na[i] == 0:
ans *= 2
ans -= 1
print(ans - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in finding the total required count.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement.
------ Output Format ------
For each test case, output the total number of integers K which satisfy the requirements mentioned.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, X ≤ 2^{30} - 1$
------ subtasks ------
Subtask 1 (10 points): $1 ≤ M ≤ 10$
Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$.
Subtask 3 (70 points): No further constraints.
----- Sample Input 1 ------
3
4 5
8 4
1 2
----- Sample Output 1 ------
0
4
1
----- explanation 1 ------
Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K
< 4$, and $(4 \oplus K) \And 5 = 0$.
- $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$
- $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$
So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
|
for _ in range(int(input())):
m, ans = 1, 0
N, X = list(map(int, input().split()))
i = 0
while True:
if X & 1 << i:
i += 1
continue
if N & 1 << i:
ans += m
m = 2 * m
if 1 << i > max(N, X):
break
i += 1
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in finding the total required count.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement.
------ Output Format ------
For each test case, output the total number of integers K which satisfy the requirements mentioned.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, X ≤ 2^{30} - 1$
------ subtasks ------
Subtask 1 (10 points): $1 ≤ M ≤ 10$
Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$.
Subtask 3 (70 points): No further constraints.
----- Sample Input 1 ------
3
4 5
8 4
1 2
----- Sample Output 1 ------
0
4
1
----- explanation 1 ------
Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K
< 4$, and $(4 \oplus K) \And 5 = 0$.
- $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$
- $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$
So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
|
t = int(input())
for _ in range(t):
n, x = map(int, input().split())
ans = p = 0
for i in range(0, 30):
if not x & 1 << i:
if n & 1 << i:
ans += 1 << p
p += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in finding the total required count.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement.
------ Output Format ------
For each test case, output the total number of integers K which satisfy the requirements mentioned.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, X ≤ 2^{30} - 1$
------ subtasks ------
Subtask 1 (10 points): $1 ≤ M ≤ 10$
Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$.
Subtask 3 (70 points): No further constraints.
----- Sample Input 1 ------
3
4 5
8 4
1 2
----- Sample Output 1 ------
0
4
1
----- explanation 1 ------
Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K
< 4$, and $(4 \oplus K) \And 5 = 0$.
- $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$
- $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$
So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
|
for _ in range(int(input())):
n, x = map(int, input().split())
n1 = 0
n2 = 0
x1 = n
x2 = x
while x1 > 0:
n1 += 1
x1 = x1 >> 1
while x2 > 0:
n2 += 1
x2 = x2 >> 1
x1 = n
x2 = x
ans = 1
while n1 >= 0:
if x2 & 1 << n1 > 0:
ans *= 1
elif x1 & 1 << n1 > 0:
ans *= 2
else:
ans = ans * 2 - 1
n1 -= 1
print(ans - 1)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Chef has two non negative integers N and X. He now wants to find the number of integers K such that 0 ≤ K < N, and (N \oplus K) \And X = 0.
Note that \oplus denotes the bitwise XOR operator and \And denotes the bitwise AND operator.
Help Chef in finding the total required count.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single line of input containing N and X denoting the two integers as described in the statement.
------ Output Format ------
For each test case, output the total number of integers K which satisfy the requirements mentioned.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N, X ≤ 2^{30} - 1$
------ subtasks ------
Subtask 1 (10 points): $1 ≤ M ≤ 10$
Subtask 2 (20 points): The sum of $N$ across all test cases won't exceed $20$.
Subtask 3 (70 points): No further constraints.
----- Sample Input 1 ------
3
4 5
8 4
1 2
----- Sample Output 1 ------
0
4
1
----- explanation 1 ------
Testcase 1: $N = 4, X = 5$. So we need to find the number of $K$, which satisfy $0 ≤ K
< 4$, and $(4 \oplus K) \And 5 = 0$.
- $(100_{2} \oplus 000_{2}) \And 101_{2} = 100_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 001_{2}) \And 101_{2} = 101_{2} \And 101_{2} = 101_{2} \neq 0$
- $(100_{2} \oplus 010_{2}) \And 101_{2} = 110_{2} \And 101_{2} = 100_{2} \neq 0$
- $(100_{2} \oplus 011_{2}) \And 101_{2} = 111_{2} \And 101_{2} = 101_{2} \neq 0$
So, we have looked at all values of $K$, and found no value which satisfies the requirements. So the answer is $0$.
|
def dfs(ind, g):
if ind < 0:
return 1
if dp[ind][g] != -1:
return dp[ind][g]
res = 0
if X >> ind & 1:
res += dfs(ind - 1, g)
elif N >> ind & 1:
res += dfs(ind - 1, g)
res += dfs(ind - 1, 0)
else:
res += dfs(ind - 1, g)
if g == 0:
res += dfs(ind - 1, g)
dp[ind][g] = res
return dp[ind][g]
T = int(input())
for i in range(T):
N, X = [int(x) for x in input().split()]
dp = [[(-1) for i in range(2)] for j in range(55)]
print(dfs(39, 1) - 1)
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR NUMBER RETURN VAR VAR VAR ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.