description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
l = list(map(int, input().split()))
a = [0] * (10**5 + 7)
for i in l:
a[i] = a[i] + 1
c = 0
if x == 0:
ans = 0
for i in l:
ans = ans + a[i] - 1
print(ans // 2)
exit()
for i in l:
z = i ^ x
if z > 10**5 + 3:
continue
c = c + a[z]
print(c // 2) | 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 BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a = list(map(int, input().split()))
c = [0] * 100101
for ai in a:
c[ai] += 1
if x == 0:
s = sum([(ci * (ci - 1)) for ci in c if ci > 1])
else:
s = 0
for i in range(1, 100101):
if i ^ x < 100101:
s += c[i] * c[i ^ x]
print(int(s / 2)) | 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 VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, q = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
f = {}
for i in a:
y = i ^ q
z = f.get(y)
if z != None:
ans += z
if f.get(i) != None:
f[i] += 1
else:
f[i] = 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NONE VAR VAR IF FUNC_CALL VAR VAR NONE VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
d = {}
a = 0
for i in map(int, input().split()):
d[i] = d.get(i, 0) + 1
for i in d:
a += [d[i] * (d[i] - 1), d.get(i ^ x, 0) * d[i]][i != i ^ x]
print(a // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR LIST BIN_OP VAR VAR BIN_OP VAR VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | old = [0] * 100001
new = [0] * 100001
n, x = (int(z) for z in input().split())
s = [int(z) for z in input().split()]
for i in s:
old[i] += 1
if i ^ x < 100001:
new[i ^ x] += 1
ans = 0
for i in range(100001):
ans += old[i] * new[i]
if x == 0:
ans -= old[i]
ans //= 2
print(ans) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER 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 FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR VAR VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | def solve():
n, x = map(int, input().split())
a = list(map(int, input().split()))
d = {}
g = []
cnt = 0
for i in a:
if d.get(i) == None:
d[i] = 1
else:
d[i] += 1
for i in a:
r = i ^ x
if d.get(r) != None and i != r:
cnt += d[r]
elif d.get(r) != None and i == r:
cnt += d[r] - 1
print(cnt // 2)
solve() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NONE VAR VAR VAR VAR VAR IF FUNC_CALL VAR VAR NONE VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | def cin():
return list(map(int, input().split()))
N = int(1000000.0 + 5)
n, x = cin()
A = cin()
B = [0] * N
an = 0
for i in A:
an += B[i ^ x]
B[i] += 1
print(an) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
arr = list(map(int, input().split()))
dict1 = {}
for i in range(n):
try:
dict1[arr[i]] += 1
except:
KeyError
dict1[arr[i]] = 1
ans = 0
if x == 0:
for i in dict1.keys():
ans += dict1[i] * (dict1[i] - 1)
print(ans // 2)
else:
for i in range(n):
val = arr[i] ^ x
try:
ans += dict1[val]
except:
KeyError
print(ans // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split(" "))
L = list(map(int, input().split()))
L = sorted(L)
P = [0] * (L[n - 1] + 1)
i = 0
while i < n:
c = 1
while i + c < n and L[i + c] == L[i]:
c = c + 1
P[L[i]] += c
i = i + c
def binary_search(arr, l, r, x):
while l <= r:
mid = l + (r - l) // 2
if arr[mid] == x:
return mid
elif arr[mid] < x:
l = mid + 1
else:
r = mid - 1
return -1
count = 0
for i in range(n):
a = L[i] ^ x
b = binary_search(L, 0, n - 1, a)
if b != -1 and b != i:
count += P[L[b]]
print(count // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | inp = lambda: map(int, input().split())
n, x = inp()
a = [*inp()]
f = [0] * (10**6 + 1)
ans = 0
for i in a:
ans += f[i ^ x]
f[i] += 1
print(ans) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n1 = input("")
m1 = input("")
n = n1.split(" ")
m = m1.split(" ")
ans = 0
x = int(n[1])
lst = {}
for i in m:
a = int(i)
if a ^ x in lst:
ans += lst[a ^ x]
if a in lst:
lst[a] += 1
else:
lst[a] = 1
print(ans) | 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 NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | from sys import stdin, stdout
n, x = map(int, stdin.readline().split())
ar = list(map(int, stdin.readline().split()))
mp = {}
c = 0
for i in range(n):
c += mp.get(ar[i] ^ x, 0)
mp[ar[i]] = mp.get(ar[i], 0) + 1
stdout.write(str(c) + "\n") | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | import sys
n, x = map(int, input().split())
arr = list(map(int, input().split()))
store = [0] * 1000000
cnt = 0
for i in range(n):
num = arr[i] ^ x
if store[arr[i] - 1] == 0:
store[num - 1] += 1
elif store[arr[i] - 1] >= 1:
cnt += store[arr[i] - 1]
store[num - 1] += 1
print(cnt) | IMPORT 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 NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
ip = list(map(int, input().split()))
count = 0
counts = [(0) for i in range(100001)]
for i in ip:
counts[i] += 1
for i in range(n):
b = x ^ ip[i]
counts[ip[i]] -= 1
try:
count += counts[b]
except:
b = 1
print(count) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
m = [0] * (1000000 + 1)
ans = 0
for i in range(n):
b = a[i] ^ x
ans += m[b]
m[a[i]] += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
cnt = [0] * (1 << 18)
arr = list(map(int, input().split()))
ans = 0
for i in range(n - 1, -1, -1):
temp = arr[i] ^ x
ans += cnt[temp]
cnt[arr[i]] += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
d = {}
s = set(a)
for i in a:
d[i] = 0
for i in a:
d[i] += 1
ans = 0
for i in s:
if x == 0:
ans += d[i] * (d[i] - 1) // 2
else:
ans += d[i] * d.get(i ^ x, 0)
if x == 0:
print(ans)
else:
print(ans // 2) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | someDict = {}
def sumOfNumbers(m):
return (m - 1) * m // 2
class Pair:
def __init__(self, k, y):
self.k = k
self.y = y
a, x = map(lambda x: int(x), input().split())
arr = list(map(lambda x: int(x), input().split()))
for i in arr:
if i in someDict.keys() or i ^ x in someDict.keys():
if i in someDict.keys():
someDict[i].k += 1
elif i ^ x in someDict.keys():
someDict[i ^ x].y += 1
else:
someDict[i] = Pair(1, 0)
counter = 0
if x == 0:
for i in someDict.values():
counter += sumOfNumbers(i.k)
print(counter)
else:
for i in someDict.values():
counter += i.k * i.y
print(counter) | ASSIGN VAR DICT FUNC_DEF RETURN BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR 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 FOR VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a, s = [0] * 100001, 0
for i in map(int, input().split()):
a[i] += 1
for i in range(100001):
if not x:
s += a[i] * (a[i] - 1) // 2
a[i] = 0
elif x ^ i < 100001:
s += a[i] * a[x ^ i]
a[i] = a[x ^ i] = 0
print(s) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
l, res = [0] * 131073, 0
for a in map(int, input().split()):
res, l[a] = res + l[a ^ x], l[a] + 1
print(res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = list(map(int, input().split()))
a = list(map(int, input().split()))
if x == 0:
ans = 0
s = dict()
for elem in a:
if elem in s:
s[elem] += 1
else:
s[elem] = 1
for key in list(s.keys()):
ans += s[key] * (s[key] - 1)
else:
ans = 0
s = dict()
for elem in a:
if elem in s:
s[elem] += 1
else:
s[elem] = 1
for key in list(s.keys()):
if key ^ x in s:
ans += s[key] * s[key ^ x]
print(ans // 2) | 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 IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | q = 1
for _ in range(q):
n, k = map(int, input().split())
l = list(map(int, input().split()))
a = [0] * (10**5 + 1)
for i in range(n):
a[l[i]] += 1
ans = 0
for i in range(n):
x = l[i] ^ k
if x <= 10**5:
if x == l[i]:
ans += a[l[i]] - 1
else:
ans += a[x]
print(ans // 2) | ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER IF VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | s = input().split()
n = int(s[0])
m = int(s[1])
a = [int(x) for x in input().split()]
frq = [0] * 100001
for i in range(n):
frq[a[i]] += 1
ans = 0
for i in range(n):
p = a[i] ^ m
if p < 100001:
if a[i] != p:
ans += frq[p]
else:
ans += frq[p] - 1
ans = int(ans / 2)
print(ans) | ASSIGN 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | temp = input().split()
n = int(temp[0])
x = int(temp[1])
temp = input().split()
a = [int(k) for k in temp]
c = [(0) for i in range(10**5 + 1)]
for i in range(n):
c[a[i]] += 1
ans = 0
for i in range(n):
if a[i] ^ x <= 10**5:
ans += c[a[i] ^ x]
if x == 0:
ans -= n
ans = int(ans / 2)
print(ans) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR BIN_OP NUMBER NUMBER VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | R = lambda: map(int, input().split())
n, x = R()
cnts = {}
res = 0
for num in R():
res += cnts.get(num, 0)
cnts[x ^ num] = cnts.get(x ^ num, 0) + 1
print(res) | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
table = {}
for a in map(int, input().split()):
if a in table:
table[a] += 1
else:
table[a] = 1
ans = 0
for i in table.keys():
if table[i] > 0:
if i ^ x in table:
if i == i ^ x:
ans += table[i] * (table[i] - 1) // 2
else:
ans += table[i] * table[i ^ x]
table[i ^ x] = 0
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | class CodeforcesTask742BSolution:
def __init__(self):
self.result = ""
self.n_x = []
self.array = []
def read_input(self):
self.n_x = [int(x) for x in input().split(" ")]
self.array = [int(x) for x in input().split(" ")]
def process_task(self):
nums = {}
for a in self.array:
if a in nums:
nums[a] += 1
else:
nums[a] = 1
pair_cnt = 0
for a in self.array:
b = a ^ self.n_x[1]
if b != a:
if b in nums:
pair_cnt += nums[b]
elif nums[b] > 1:
pair_cnt += nums[b] - 1
self.result = str(pair_cnt // 2)
def get_result(self):
return self.result
Solution = CodeforcesTask742BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result()) | CLASS_DEF FUNC_DEF ASSIGN VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_DEF RETURN VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = [int(i) for i in input().split()]
ans = 0
d = {}
for i in map(int, input().split()):
ans += d.get(i ^ x, 0)
d[i] = d.get(i, 0) + 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a = [int(i) for i in input().split()]
m = dict()
for i in a:
if not i in m:
m[i] = 1
else:
m[i] += 1
s = 0
for i in m:
j = x ^ i
if j in m:
if i == j:
s += m[i] * (m[i] - 1)
else:
s += m[i] * m[j]
print(s // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a = [int(x) for x in input().split()]
def summ(n):
ans = 0
for i in range(n):
ans += i
return ans
ad = {}
count = 0
for i in a:
ad[i] = ad.get(i, 0) + 1
if x:
for i in ad:
count += ad[i] * ad.get(i ^ x, 0)
print(int(count // 2))
else:
for i in ad:
count += summ(ad[i])
print(count) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR FOR VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
cs = {}
for v in a:
cs[v] = cs.get(v, 0) + 1
t = 0
if x == 0:
for c in cs.values():
t += c * (c - 1) // 2
print(t)
else:
for v in a:
t += cs.get(x ^ v, 0)
print(t // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for p in a:
if p not in d:
d[p] = 1
else:
d[p] += 1
cnt = 0
if x == 0:
for k in d:
cnt += d[k] * (d[k] - 1) // 2
print(cnt)
else:
for k in d:
if k ^ x in d:
cnt += d[k] * d[k ^ x]
print(cnt // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | def get_row():
return [int(x) for x in input().split()]
_, x = get_row()
a = get_row()
counts = {}
count = 0
for n in reversed(a):
count += counts.get(n ^ x, 0)
counts[n] = counts.get(n, 0) + 1
print(count) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
ar = list(map(int, input().split()))
st = {}
soln = 0
for el in ar:
if el ^ x in st:
soln += st[el ^ x]
if el in st:
st[el] += 1
else:
st[el] = 1
print(soln) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
d = {}
for k in a:
if d.get(k ^ x, 0) > 0:
ans += d.get(k ^ x)
d[k] = d.get(k, 0) + 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
count = 0
d = {}
l = list(map(int, input().split()))
inp = l[0]
d[inp] = 1
for i in range(1, n):
inp = l[i]
xor = x ^ inp
if xor in d:
count += d[xor]
if inp not in d:
d[inp] = 0
d[inp] += 1
print(count) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
arr = list(map(int, input().split()))
b = [0] * int(200000.0)
for i in arr:
b[i] += 1
res = 0
for i in arr:
r = i ^ x
res += b[r]
if x == 0:
res -= len(arr)
print(res // 2) | 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 FUNC_CALL VAR NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | from sys import stdin
input = stdin.buffer.readline
n, x = map(int, input().split())
(*a,) = map(int, input().split())
cnt = [0] * 200001
res = 0
for i in a:
res += cnt[x ^ i]
cnt[i] += 1
print(res) | ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
d1 = {}
for a in A:
if a in d1:
d1[a] += 1
else:
d1[a] = 1
keys = list(d1.keys())
keys.sort()
ans = 0
for k in keys:
b = k ^ x
if b > k:
if b in d1:
ans += d1[b] * d1[k]
elif b == k:
ans += d1[b] * (d1[b] - 1) // 2
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
mp = {i: (0) for i in l}
for i in l:
mp[i] += 1
for i in l:
mp[i] -= 1
if i ^ x in mp.keys():
ans += mp[i ^ x]
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR FOR VAR VAR VAR VAR NUMBER FOR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = list(map(int, input().split()))
if x == 0:
ans = -n
else:
ans = 0
a = list(map(int, input().split()))
b = {}
for i in a:
if i in b:
b[i] += 1
else:
b[i] = 1
for i in a:
k = i ^ x
if k in b:
ans += b[k]
print(ans // 2) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
arr = list(map(int, input().split()))
dict = {}
for v in arr:
if v in dict:
dict[v] += 1
else:
dict[v] = 1
if x:
res = 0
for v in dict.keys():
if v ^ x in dict and v ^ x > v:
res += dict[v] * dict[v ^ x]
print(res)
else:
print(sum(map(lambda x: x * (x - 1) // 2, dict.values()))) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
l = list(map(int, input().split()))
d = {}
ans = 0
for i in l:
d[i] = d.get(i, 0) + 1
if x == 0:
ans -= n
for y in d:
ans += d[y] * (d[y] + 1) // 2
else:
for y in d:
t = x ^ y
ans += d[y] * d.get(t, 0)
d[y] = 0
print(max(0, ans)) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR VAR FOR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | LIMIT = 1103 + int(10000000.0)
a = [0] * LIMIT
n, x = map(int, input().split(" "))
r = 0
for k in [int(y) for y in input().split(" ")]:
r += a[x ^ k]
a[k] += 1
print(r) | ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
cnt = [(0) for i in range(100010)]
arr = list(map(int, input().split()))
for num in arr:
cnt[num] += 1
ans = 0
for num in arr:
xor_num = x ^ num
if xor_num > 100000:
continue
cnt[num] -= 1
if cnt[xor_num] > 0:
ans += cnt[xor_num]
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | def ri():
return map(int, input().split())
n, x = ri()
cnt = 0
dd = {}
for i in ri():
if i in dd:
dd[i] += 1
else:
dd[i] = 1
xx = i ^ x
if xx in dd:
cnt += dd[xx]
if x == 0:
cnt -= 1
print(int(cnt)) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a = list(map(int, input().split()))
count = {}
ans = 0
for i in range(n):
if a[i] in count:
count[a[i]] += 1
else:
count[a[i]] = 1
for i in range(n):
val = a[i]
if val ^ x in count:
ans += count[val ^ x]
if val ^ x == val:
ans -= 1
print(ans // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
ax = [(i ^ x) for i in a]
a.sort()
ax.sort()
pos = 0
posx = 0
c = 1
cx = 1
total = 0
while pos < n and posx < n:
if a[pos] == ax[posx]:
if pos < n - 1 and a[pos + 1] == a[pos]:
pos += 1
c += 1
elif posx < n - 1 and ax[posx + 1] == ax[posx]:
posx += 1
cx += 1
else:
total += c * cx
c = 1
cx = 1
pos += 1
posx += 1
elif a[pos] > ax[posx]:
posx += 1
else:
pos += 1
if x > 0:
print(total // 2)
else:
print((total - n) // 2) | 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 BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR IF VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | N = 10**5 + 1
n, x = list(map(int, input().split()))
A = list(map(int, input().split()))
B = [0] * N
for a in A:
B[a] += 1
res = 0
for i in range(N):
if i ^ x < N:
res += B[i] * B[i ^ x]
print((res - n) // 2 if x == 0 else res // 2) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | _, n = map(int, input().split())
M = {}
ans = 0
for x in map(int, input().split()):
ans += M.get(x ^ n, 0)
if x not in M:
M[x] = 1
else:
M[x] += 1
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | def main():
n, x = list(map(int, input().split()))
l, res = [0] * 131073, 0
for a in map(int, input().split()):
res += l[a ^ x]
l[a] += 1
print(res)
def __starting_point():
main()
__starting_point() | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | line = input().split()
N = int(line[0])
X = int(line[1])
line = input().split()
arr = [0] * 1000000
for i in range(N):
arr[int(line[i])] += 1
res = 0
for i in range(len(arr)):
if i ^ X < len(arr):
if arr[i] > 0:
if i == i ^ X:
res += arr[i] * (arr[i] - 1) // 2
else:
res += arr[i] * arr[i ^ X]
arr[i] = 0
arr[i ^ X] = 0
print(res) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | [n, y] = map(int, input().split())
cnt = {}
ans = 0
a = list(map(int, input().split()))
for i in a:
if y ^ i in cnt:
ans += cnt[y ^ i]
if i in cnt:
cnt[i] += 1
else:
cnt[i] = 1
print(ans) | ASSIGN LIST VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | def rints():
return list(map(int, input().split()))
def ri():
return int(input())
MAX_A = 10**5
n, x = rints()
arr = rints()
seen = [0] * (MAX_A + 1)
count = 0
for elem in arr:
partner = x ^ elem
if partner <= MAX_A:
count += seen[partner]
seen[elem] += 1
print(count) | FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
al = [0] * 1000005
m = 0
dl = list(map(int, input().split()))
ms = set(dl)
for i in dl:
al[i] += 1
m = max(i, m)
ans = 0
for i in ms:
j = i ^ x
if al[i] > 0 and al[j] > 0:
if i != j:
ans += al[i] * al[j]
else:
ans += al[i] * (al[i] - 1) // 2
al[i] = 0
al[j] = 0
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are some beautiful girls in Arpa’s land as mentioned before.
Once Arpa came up with an obvious problem:
Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation).
[Image]
Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.
-----Input-----
First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x.
Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array.
-----Output-----
Print a single integer: the answer to the problem.
-----Examples-----
Input
2 3
1 2
Output
1
Input
6 1
5 1 2 3 4 1
Output
2
-----Note-----
In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1.
In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$).
A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. | n, x = map(int, input().split())
a = list(map(int, input().split()))
chk = []
ans = 0
for i in range(0, 100001, 1):
chk.append(0)
for i in range(0, n, 1):
chk[a[i]] += 1
for i in range(0, 100001, 1):
if i ^ x <= 100000:
if i == i ^ x:
ans += chk[i] * (chk[i] - 1)
else:
ans += chk[i] * chk[i ^ x]
print(ans // 2) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = input().split(" ")
n = int(n)
k = int(k)
a = [int(x) for x in input().split(" ")]
c = 0
a.sort()
m = n
index = n
temp = 1
for i in range(n):
temp *= a[i]
if a[i] > k:
if c == 0:
index = i
c += 2 ** (m - 1)
m -= 1
if temp <= k:
a = []
a = a[:index]
flag = 0
ctr = a.count(1)
if ctr > 0:
a = a[ctr:]
flag = 1
product = [1]
p = []
for i in range(len(a)):
for j in range(len(product)):
if product[j] * a[i] > k:
if flag:
c += 2**ctr * 2 ** (len(a) - i - 1) * (len(product) - j)
else:
c += 2 ** (len(a) - i - 1) * (len(product) - j)
break
p.append(product[j] * a[i])
product += p
product.sort()
p = []
print(2**n - 1 - c) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR LIST ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR IF VAR VAR BIN_OP BIN_OP BIN_OP NUMBER VAR BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | string = input()
val = string.split()
int_val = [int(o) for o in val]
N, K = int_val
line = input()
l = line.split()
int_l = [int(x) for x in l]
int_l.sort()
nonones = []
for i in int_l:
if i != 1:
nonones.append(i)
noofones = len(int_l) - len(nonones)
list = [1]
count = 0
for i in nonones:
list_temp = []
for j in list:
if i * j <= K:
list_temp.append(i * j)
count += 1
else:
break
list.extend(list_temp)
list.sort()
print(int(count * 2**noofones + (2**noofones - 1))) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP BIN_OP NUMBER VAR NUMBER |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = map(int, input().split())
d = []
s = 0
ac = 0
l = list(map(int, input().split()))
cnt1 = l.count(1)
for i in range(n):
if i == 0 and l[i] != 1:
if l[i] <= k:
d.append(l[i])
s += 1
ac += 1
else:
asd = ac
z = 0
if l[i] <= k and l[i] != 1:
for j in range(ac):
x = l[i] * d[j]
if x <= k:
s += 1
d.append(x)
z += 1
d.append(l[i])
z += 1
s += 1
ac += z
s = (pow(2, cnt1) - 1) * (1 + s) + s
print(s) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = map(int, input().split())
a = list(map(int, input().split()))
def f(i, p):
if p > k:
return 0
if i == -1:
return 1
if p not in dp[i]:
dp[i][p] = f(i - 1, p) + f(i - 1, p * a[i])
return dp[i][p]
dp = [{} for i in range(n)]
ans = f(n - 1, 1) - 1
print(ans) | 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 FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR VAR VAR ASSIGN VAR DICT VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = map(int, input().split())
l = list(map(int, input().split()))
onecount = l.count(1)
dlist = list()
s, ac = 0, 0
asd, z = 0, 0
for i in range(n):
t = l[i]
if i == 0 and t != 1:
if t <= k:
dlist.append(t)
s = s + 1
ac = ac + 1
else:
asd = ac
z = 0
if t <= k and t != 1:
for j in range(ac):
x = t * dlist[j]
if x <= k:
s = s + 1
dlist.append(x)
z = z + 1
dlist.append(t)
z = z + 1
s = s + 1
ac += z
res = (pow(2, onecount) - 1) * (1 + s) + s
print(res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n = input()
r = list(map(int, n.split()))
k = r[1]
arr = input()
li = list(map(int, arr.split()))
def count(li, k):
li.sort()
if li[0] > k:
print(0)
return
l = len(li)
if l == 1:
if li[0] <= k:
print(1)
return
li1 = li[: int(len(li) / 2)]
li2 = li[int(len(li) / 2) : len(li)]
nl1 = count1(li1, k)
nl2 = count1(li2, k)
count = 0
count = len(nl1) + len(nl2)
nl1.sort()
nl2.sort()
l1 = len(nl1)
l2 = len(nl2)
i = l1 - 1
j = 0
while i >= 0:
d = k / nl1[i]
while j < l2:
if nl2[j] > d:
break
j = j + 1
if j > 0:
count = count + j
i = i - 1
print(count)
def count1(li, k):
nl = []
i = 0
if li[0] > k:
return nl
if li[0] <= k:
nl.append(li[i])
i = i + 1
pr = 0
while i < len(li):
a = len(nl)
d1 = k / li[i]
for j in range(a):
pr = li[i] * nl[j]
if nl[j] <= d1:
nl.append(pr)
if li[i] <= k:
nl.append(li[i])
i = i + 1
return nl
count(li, k) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR WHILE VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER VAR RETURN VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = map(int, input().strip().split())
arr = list(map(int, input().strip().split()))
l1 = [1]
l2 = [1]
def get_possibilities(no):
start = 0
l2_len = len(l2)
end = l2_len - 1
if l2[end] * no <= k:
return l2_len
while start <= end:
mid = (start + end) // 2
if mid == l2_len - 1:
return 0
elif l2[mid] * no <= k and l2[mid + 1] * no > k:
return mid + 1
elif l2[mid] * no <= k:
start = mid + 1
else:
end = mid - 1
return 0
for i in arr[: n // 2]:
l1_len = len(l1)
for j in l1[:l1_len]:
if i * j <= k:
l1.append(i * j)
for i in arr[n // 2 :]:
l2_len = len(l2)
for j in l2[:l2_len]:
if i * j <= k:
l2.append(i * j)
l2.sort()
ans = -1
for i in l1:
ans += get_possibilities(i)
print(ans) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR LIST NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR RETURN VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FOR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = list(map(int, input().split()))
ar = list(map(int, input().split()))
def proc(l, r):
prod = []
sz = r - l
for mask in range(1, 1 << sz):
res = 1
for i in range(l, r):
if mask & 1 << i - l:
res *= ar[i]
prod.append(res)
prod.sort()
return prod
left, right = list(reversed(proc(0, n // 2))), proc(n // 2, n)
ans = 0
for it in left:
if it <= k:
ans += 1
for it in right:
if it <= k:
ans += 1
j = 0
for i in range(len(left)):
while j < len(right) and left[i] * right[j] <= k:
j += 1
ans += j
print(ans) | 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 FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR BIN_OP NUMBER BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | i = input()
s = i.split()
N = eval(s[0])
K = eval(s[1])
arrElem = input()
a = arrElem.split()
A = []
totsets = 2**N - 1
count = 0
for i in range(0, N):
A.append(eval(a[i]))
A.sort()
prod = []
req = []
count1 = 0
for i in range(0, N):
if A[i] <= K and A[i] != 1:
req.append(A[i])
elif A[i] == 1:
count1 = count1 + 1
noOfOnesSubsets = 2**count1 - 1
for i in range(0, len(req)):
prod.sort()
l = len(prod)
if req[i] <= K:
prod.append(req[i])
for j in range(0, l):
if req[i] * prod[j] <= K:
prod.append(req[i] * prod[j])
else:
break
count = len(prod)
print((count + 1) * noOfOnesSubsets + count) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | import sys
def solve(A, n, k):
if n == 1:
return {A[0]: 1}
h = solve(A, n - 1, k)
hNew = {}
for x in h:
hNew[x] = h[x]
for x in h:
temp = x * A[n - 1]
if temp <= k:
if not temp in hNew:
hNew[temp] = 0
hNew[temp] += h[x]
if not A[n - 1] in hNew:
hNew[A[n - 1]] = 0
hNew[A[n - 1]] += 1
return hNew
n, k = map(int, input().split())
A = [x for x in list(map(int, input().split())) if x <= k]
n = min(n, len(A))
if n == 0:
print(0)
else:
h = solve(A, n, k)
print(sum(h.values())) | IMPORT FUNC_DEF IF VAR NUMBER RETURN DICT VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | N, k = list(map(int, input().split()))
a = list(map(int, input().split()))
lA = []
lB = []
def recA(i, chosen, n, mul, k):
if i == n:
if mul <= k and chosen != 0:
lA.append(mul)
return
recA(i + 1, chosen + 1, n, mul * a[i], k)
recA(i + 1, chosen, n, mul, k)
def recB(i, chosen, n, mul, k):
if i == n:
if mul <= k and chosen != 0:
lB.append(mul)
return
recB(i + 1, chosen + 1, n, mul * a[i], k)
recB(i + 1, chosen, n, mul, k)
def bsearch(aa, k):
l = 0
r = len(lB)
b = k // aa
while l < r:
mid = (l + r) // 2
if lB[mid] > b:
r = mid
elif lB[mid] < b:
l = mid + 1
else:
l = mid + 1
return r
recA(0, 0, N // 2, 1, k)
recB(N // 2, 0, N, 1, k)
lA.sort()
lB.sort()
res = 0
for i in lA:
if i <= k:
res += 1
for i in lB:
if i <= k:
res += 1
for i in lA:
res += bsearch(i, k)
print(res) | 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 LIST FUNC_DEF IF VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_DEF IF VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
left = []
right = []
for i in range(n // 2):
sz = len(left)
for j in range(sz):
left.append(left[j] * arr[i])
left.append(arr[i])
for i in range(n // 2, n):
sz = len(right)
for j in range(sz):
right.append(right[j] * arr[i])
right.append(arr[i])
left.sort()
right.sort()
ans = 0
for i in left:
if i <= k:
ans += 1
for j in right:
if j <= k:
ans += 1
for i in left:
lo = 0
hi = len(right) - 1
while lo < hi:
md = lo + (hi - lo + 1) // 2
if right[md] * i <= k:
lo = md
else:
hi = md - 1
if i * right[hi] <= k:
ans += hi + 1
print(ans) | 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 ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def solve(l, idx, n, k, p, t):
if p > k:
return None
if idx == n:
t.append(p)
return None
solve(l, idx + 1, n, k, p, t)
solve(l, idx + 1, n, k, p * l[idx], t)
def search(l, k, val):
lo = 1
hi = len(l) - 1
ans = len(l)
while lo <= hi:
mid = (lo + hi) // 2
if val * l[mid] > k:
hi = mid - 1
else:
ans = mid
lo = mid + 1
return ans
n, k = map(int, input().split())
l = list(map(int, input().split()))
t = []
d = []
solve(l, 0, n // 2, k, 1, t)
solve(l, n // 2, n, k, 1, d)
ans = len(t) + len(d) - 2
t.sort()
d.sort()
for i in t[1:]:
idx = search(d, k, i)
if idx != len(d):
ans += idx
print(ans) | FUNC_DEF IF VAR VAR RETURN NONE IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN NONE EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def q6(nums, k, d):
for i in range(len(nums)):
current = nums[i]
if current > k:
continue
currentDict = dict()
for elem in d:
new = current * elem
if new <= k:
currentDict[new] = d[elem]
for elem in currentDict:
if elem not in d:
d[elem] = currentDict[elem]
else:
d[elem] += currentDict[elem]
if current in d:
d[current] += 1
else:
d[current] = 1
def main():
line = input()
k = line.split(" ")[1]
nums = list(map(int, input().split(" ")))
d = dict()
q6(nums, int(k), d)
counter = 0
for p in d:
counter += d[p]
print(counter)
main() | FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def numOfSub(integers, K, product, index):
if product > K:
return 0
if index == len(integers):
return 1
return numOfSub(integers, K, product * integers[index], index + 1) + numOfSub(
integers, K, product, index + 1
)
def buildStart(integers):
result = []
for i in range(len(integers) - 1):
result.append((integers[i + 1 :], integers[i]))
return result
def buildCont(sets, K):
result = []
for i in range(len(sets)):
for j in range(len(sets[i][0])):
if sets[i][0][j] * sets[i][1] <= K:
result.append(
(sets[i][0][:j] + sets[i][0][j + 1 :], sets[i][0][j] * sets[i][1])
)
return result
def solve(integers, K):
result = buildStart(integers)
counter = len(result) + 1
while len(result) > 0:
result = buildCont(result, K)
counter += len(result)
return counter
def solve3(integers, K):
helper = {}
for i in integers:
tmp = {}
for j in helper:
if j * i <= K:
tmp[i * j] = helper[j]
for j in tmp:
if j in helper:
helper[j] += tmp[j]
else:
helper[j] = tmp[j]
if i not in helper:
helper[i] = 0
helper[i] += 1
result = 0
for j in helper:
result += helper[j]
return result
N, K = input().split(" ")
N, K = int(N), int(K)
arrStr = input().split(" ")
integers = [int(a) for a in arrStr if int(a) <= K]
print(solve3(integers, K)) | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR DICT FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR FOR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = {}
m[a[0]] = 1
for i in range(1, n):
m_temp = m.copy()
if a[i] in m_temp.keys():
m_temp[a[i]] = m_temp[a[i]] + 1
else:
m_temp[a[i]] = 1
for j in m:
if j * a[i] > k:
continue
if j * a[i] in m_temp.keys():
m_temp[j * a[i]] += m[j]
else:
m_temp[j * a[i]] = m[j]
m = m_temp
ans = 0
for j in m:
if j > k:
continue
ans += m[j]
print(ans) | 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 ASSIGN VAR DICT ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def p(s, t):
count = 0
lst = []
pro = []
for i in range(0, len(s)):
if int(s[i]) == 1:
count = count + 1
elif int(s[i]) <= t:
lst.append(int(s[i]))
lst.sort()
pro.append(1)
for k in range(0, len(lst)):
pro.sort()
curr = len(pro)
for j in range(0, curr):
product = lst[k] * pro[j]
if product <= t:
pro.append(product)
else:
break
set1 = len(pro) - 1
set2 = 2**count - 1
set3 = set1 * set2
return set1 + set2 + set3
line1 = input()
x = line1.split()
line2 = input()
y = line2.split()
z = p(y, int(x[1]))
print(z) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def checkProduct(index, Product):
if Product > N[1]:
return 0
if index < len(L):
return checkProduct(index + 1, Product) + checkProduct(
index + 1, Product * L[index]
)
elif Product <= N[1]:
return 1
else:
return 0
N = list(map(int, input().split()))
L = list(map(int, input().split()))
Cou = L.count(1)
L = sorted(x for x in L if x <= N[1] and x > 1)
print(checkProduct(0, 1) * 2**Cou - 1) | FUNC_DEF IF VAR VAR NUMBER RETURN NUMBER IF VAR FUNC_CALL VAR VAR RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR IF VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN 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 NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR NUMBER NUMBER BIN_OP NUMBER VAR NUMBER |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | li = list(map(int, input().split()))
N = li[0]
maxval = li[1]
cnt = 0
arr = list(map(int, input().split()))
arr.sort()
array = [1]
ind = 0
flag = 0
for j in range(N):
if arr[j] == 1:
ind = j
flag = 1
if flag == 1:
numones = ind + 1
newarr = arr[ind + 1 :]
else:
numones = 0
newarr = arr
sum1 = 0
for u in range(numones + 1):
sum1 = sum1 + u
for i in range(len(newarr)):
num = newarr[i]
l = len(array)
k = 0
for k in range(l):
pro = num * array[k]
if pro <= maxval:
array.append(pro)
else:
break
k = k + 1
array.sort()
x = 2**numones
ans2 = x - 1 + (len(array) - 1) * x
print(ans2) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def solve(a, count, m, x, n, i):
if i >= n:
return count
while i < n:
y = x
x *= a[i]
if x > m or x < y or x > 10**18:
count += pow(2, n - i - 1)
else:
z = x
j = i + 1
while j < n:
z *= a[j]
if z > m or z > 10**18:
break
j += 1
if j >= n:
return count
count = solve(a, count, m, x, n, i + 1)
x = y
i += 1
return count
def main():
n, k = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
ans = solve(arr, 0, k, 1, n, 0)
l = pow(2, n) - 1
l -= ans
print(l)
main() | FUNC_DEF IF VAR VAR RETURN VAR WHILE VAR VAR ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR BIN_OP NUMBER NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER IF VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | a = list(map(int, input().split(" ")))
n = a[0]
k = a[1]
a = list(map(int, input().split(" ")))
a1 = []
a2 = []
for i in range(len(a) // 2):
a1.append(a[i])
for i in range(len(a) // 2, len(a)):
a2.append(a[i])
p1 = []
p2 = []
for i in range(1, 1 << len(a1)):
pro = 1
for j in range(len(a1)):
if i >> j & 1 == 1:
pro = pro * a1[j]
if pro <= k:
p1.append(pro)
for i in range(1, 1 << len(a2)):
pro = 1
for j in range(len(a2)):
if i >> j & 1 == 1:
pro = pro * a2[j]
if pro <= k:
p2.append(pro)
ans = 0
p1.sort()
p2.sort()
ans = ans + len(p1) + len(p2)
ind2 = 0
p1.reverse()
for i in p1:
while ind2 < len(p2) and i * p2[ind2] <= k:
ind2 = ind2 + 1
ans = ans + ind2
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR VAR WHILE VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | r, e = input().split()
n = int(r)
val = int(e)
list = input().split()
count = 0
stuff = []
cou = 0
siu = 0
for i in list:
u = int(i)
if u < val and u != 1:
stuff.insert(count, u)
count = count + 1
if u == 1:
siu = siu + 1
li = len(stuff)
ui = li
li = int(li / 2)
puff = stuff[0:li]
kuff = stuff[li:ui]
vol1 = 2 ** len(puff) - 1
vol2 = 2 ** len(kuff) - 1
ans1 = []
ans2 = []
for i in range(1, vol1 + 1):
pro = 1
ue = 0
for j in range(0, len(puff) + 1):
if i & 1 << j:
pro = pro * puff[j]
if pro > val:
ue = 1
break
if ue == 0:
ans1.insert(0, pro)
for i in range(1, vol2 + 1):
pro = 1
ue = 0
for j in range(0, len(kuff) + 1):
if i & 1 << j:
pro = pro * kuff[j]
if pro > val:
ue = 1
break
if ue == 0:
ans2.insert(0, pro)
ans2.sort()
ans1.sort()
for i in range(0, len(ans1)):
for j in range(0, len(ans2)):
ri = ans1[i] * ans2[j]
if ri <= val:
cou = cou + 1
else:
break
ous = cou + len(ans1) + len(ans2)
an = ous
if siu >= 1:
an = 1 + 2 * ous
if siu > 1:
for i in range(1, siu):
an = 1 + an * 2
print(an) | ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = list(map(int, input().split()))
oldarray = list(map(int, input().split()))
array = []
c = 0
for i in oldarray:
if i != 1:
array.append(i)
else:
c += 1
n = n - c
newArray = []
x = 0
for i in range(n):
if array[i] <= k:
g = 0
t = 0
while g < x:
if array[i] * newArray[g] <= k:
newArray.append(array[i] * newArray[g])
t += 1
g += 1
newArray.append(array[i])
x += 1 + t
print(x * 2**c + 2**c - 1) | 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 NUMBER FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP NUMBER VAR BIN_OP NUMBER VAR NUMBER |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def solve(A, aa, k):
A.sort()
for i in range(1, 2 ** len(A)):
mul = 1
for j in range(0, len(A)):
if 2**j & i:
mul = mul * A[j]
if mul <= k:
aa.append(mul)
aa.sort()
N, K = map(int, input().split())
Arr = [int(x) for x in input().split()]
A = list()
B = list()
for i in range(1, N + 1):
if 2 * i <= N:
A.append(Arr[i - 1])
else:
B.append(Arr[i - 1])
aa = list()
bb = list()
solve(A, aa, K)
solve(B, bb, K)
result = len(aa) + len(bb)
for i in range(0, len(aa)):
b = 0
e = len(bb) - 1
idx = -1
while b <= e:
mi = (b + e) // 2
if aa[i] * bb[mi] <= K:
idx = mi
b = mi + 1
else:
e = mi - 1
result += idx + 1
print(result) | FUNC_DEF EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP BIN_OP NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR 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 FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def fun(arr, m):
d = []
for i in range(1, pow(2, len(arr))):
cnt = 1
for j in range(len(arr)):
if i & 1 << j:
cnt *= int(arr[j])
if cnt > m:
break
if cnt <= m:
d.append(cnt)
return d
def binsearch(arr, value):
high = len(arr)
low = 0
while low < high:
mid = (low + high) // 2
if arr[mid] > value:
high = mid
elif arr[mid] <= value:
low = mid + 1
return low
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = a[0 : n // 2]
c = a[n // 2 : n]
e = fun(b, m)
f = fun(c, m)
e.sort()
f.sort()
cnt = len(e) + len(f)
for i in e:
cnt += binsearch(f, m // i)
print(cnt) | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN 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 BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | memo = {}
def countSS(v, lim, curr, i):
key = "%d,%d" % (curr, i)
if i < 0:
return 0
if key in memo:
return memo[key]
cnt = 0
ii = i
while i >= 0:
mul = curr * v[i]
if mul <= lim:
cnt += 1
cnt += countSS(v, lim, mul, i - 1)
i -= 1
memo[key] = cnt
return cnt
N, K = map(int, input().split())
V = list(map(int, input().split()))
print(countSS(V, K, 1, N - 1)) | ASSIGN VAR DICT FUNC_DEF ASSIGN VAR BIN_OP STRING VAR VAR IF VAR NUMBER RETURN NUMBER IF VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR RETURN 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 NUMBER BIN_OP VAR NUMBER |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | v = []
b = []
ind = -1
l = list(map(int, input().split()))
n = l[0]
k = l[1]
arr = list(map(int, input().split()))
def compute(i, prod):
if i > ind:
return
compute(i + 1, prod)
v.append(prod * arr[i])
compute(i + 1, prod * arr[i])
def solve(i, prod):
if i == n:
return
solve(i + 1, prod)
if arr[i] > k:
return
prod *= arr[i]
if prod <= k:
b.append(prod)
solve(i + 1, prod)
def solve1(i, prod):
if i == n:
return 1
ans = solve1(i + 1, prod)
prod *= arr[i]
if prod <= k:
ans += solve1(i + 1, prod)
return ans
def upperBound(a, lo, hi, x):
if lo > hi:
return lo
mid = (lo + hi) // 2
if a[mid] == x:
return upperBound(a, mid + 1, hi, x)
elif a[mid] > x:
return upperBound(a, lo, mid - 1, x)
else:
return upperBound(a, mid + 1, hi, x)
prod = 1
for i in range(n):
prod *= arr[i]
if prod <= k:
ind += 1
else:
break
if ind > 5:
compute(0, 1)
solve(ind + 1, 1)
ans = (1 << ind + 1) - 1
v.sort()
for i in range(len(b)):
if b[i] > k:
continue
ans += 1
temp = k // b[i]
up = upperBound(v, 0, len(v) - 1, temp)
if up == len(v):
up -= 1
cnt = up + 1
while up >= 0 and v[up] > temp:
cnt -= 1
up -= 1
ans += cnt
else:
ans = solve1(0, 1) - 1
print(ans) | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR FUNC_DEF IF VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR RETURN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR IF VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | lis = input().split()
n = int(lis[0])
k = int(lis[1])
lis = input().split()
Array = []
for i in range(0, n):
Array.append(int(lis[i]))
X = []
Y = []
for i in range(0, 1 << int(n / 2)):
result = 1
for j in range(0, int(n / 2)):
if i & 1 << j:
result = result * Array[j]
X.append(result)
for i in range(0, 1 << n - int(n / 2)):
result = 1
for j in range(0, n - int(n / 2)):
if i & 1 << j:
result = result * Array[j + int(n / 2)]
Y.append(result)
szx = 1 << int(n / 2)
szy = 1 << n - int(n / 2)
Y.sort()
Count = 0
X[0] = 1
Y[0] = 1
for i in range(0, szx):
low = 0
high = szy
p = 0
while low < high:
mid = int((low + high) / 2)
if Y[mid] <= k / X[i]:
p = mid
low = mid + 1
else:
high = mid - 1
if p < szy - 1:
p = p + 1
if p == szy:
p = p - 1
while Y[p] * X[i] > k and p >= 0:
p = p - 1
if p == -1:
continue
if Y[p] * X[i] <= k:
Count = Count + (p + 1)
print(Count - 1) | ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN 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 LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
n1 = n // 2
n2 = n - n1
sa = []
sb = []
x = []
y = []
def binarySearch(req):
l = 0
h = len(y) - 1
while l <= h:
mid = (l + h) // 2
if y[mid] == req:
l = mid + 1
elif y[mid] < req:
l = mid + 1
else:
h = mid - 1
return l
for i in range(0, n1):
sa.append(a[i])
for i in range(n1, n):
sb.append(a[i])
for i in range(1, 2**n1):
r = 1
for j in range(0, n1):
if i & 2**j:
r = r * sa[j]
x.append(r)
for i in range(1, 2**n2):
r = 1
for j in range(0, n2):
if i & 2**j:
r = r * sb[j]
y.append(r)
res = 0
x.sort()
y.sort()
for i in x:
if i <= k:
res += 1
else:
break
for i in y:
if i <= k:
res += 1
else:
break
for i in range(len(x)):
req = k // x[i]
ans = binarySearch(req)
res += ans
print(res) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | g1 = []
g2 = []
r = input().split()
n = int(r[0])
k = int(r[1])
inp = [int(i) for i in input().split()]
mid = int(n / 2)
a = inp[:mid]
b = inp[mid:]
def genp(i, s):
if i == len(a):
if s != 0:
g1.append(s)
else:
genp(i + 1, s * a[i])
genp(i + 1, s)
def genp1(i, s):
if i == len(b):
if s != 0:
g2.append(s)
else:
genp1(i + 1, s * b[i])
genp1(i + 1, s)
def bin(v):
lo = 0
hi = len(g2) - 1
if hi * v <= v:
return -1
mid = int((lo + hi) / 2)
while lo <= hi:
mid = int((lo + hi) / 2)
if g2[mid] * v > k:
if g2[mid - 1] * v <= k:
return mid
hi = mid
elif g2[mid] * v <= k:
lo = mid + 1
def count():
g1.sort()
g2.sort()
ans = 0
j = len(g2) - 1
for i in range(len(g1)):
if g1[i] > k:
ans += len(g2)
continue
if g1[i] * g2[0] > k:
ans += len(g2) - 1
continue
while j > 0 and g1[i] * g2[j] > k:
j -= 1
ans += len(g2) - j - 1
return ans
def main():
genp(0, 1)
genp1(0, 1)
ans = count()
print(2**n - 1 - ans)
main() | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER BIN_OP VAR VAR VAR VAR VAR VAR NUMBER VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | lst1 = []
lst2 = []
sec_sum1 = []
sec_sum2 = []
def rec1(pos, sum):
if pos == len(lst1):
sec_sum1.append(sum)
return
rec1(pos + 1, sum * lst1[pos])
rec1(pos + 1, sum)
def rec2(pos, sum):
if pos == len(lst2):
sec_sum2.append(sum)
return
rec2(pos + 1, sum * lst2[pos])
rec2(pos + 1, sum)
def binary_search(key, high):
hi, lo, mid, ans = len(sec_sum2) - 1, 1, 0, 0
while hi >= lo:
mid = int((hi + lo) / 2)
if key * sec_sum2[mid] <= high:
lo = mid + 1
ans = mid
else:
hi = mid - 1
return ans
n, m = map(int, input().split(" "))
A = [int(a) for a in input().split()]
for i in range(0, n, 1):
if i % 2 == 0:
lst1.append(A[i])
else:
lst2.append(A[i])
rec1(0, 1)
rec2(0, 1)
sec_sum1.sort()
sec_sum2.sort()
maxi = 0
for i in range(1, len(sec_sum1), 1):
if sec_sum1[i] <= m:
maxi += 1
for i in range(1, len(sec_sum2), 1):
if sec_sum2[i] <= m:
maxi += 1
for i in range(1, len(sec_sum1), 1):
if sec_sum1[i] > m:
break
cur = binary_search(sec_sum1[i], m)
maxi += cur
print(maxi) | ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_DEF ASSIGN VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | def func(array, n, pro):
if pro > maxi:
return 0
if n == 0:
return 1
if array[n - 1] > maxi:
return func(array, n - 1, pro)
return func(array, n - 1, pro) + func(array, n - 1, pro * array[n - 1])
su = 0
li = list(map(int, input().split()))
N = li[0]
maxi = li[1]
cnt = 0
arr = list(map(int, input().split()))
arr.sort()
ind = 0
flag = 0
for i in range(N):
if arr[i] == 1:
ind = i
flag = 1
if flag == 1:
numones = ind + 1
newarr = arr[ind + 1 :]
else:
numones = 0
newarr = arr
num = func(newarr, len(newarr), 1)
y = 2**numones
z = y - 1 + (num - 1) * y
print(z) | FUNC_DEF IF VAR VAR RETURN NUMBER IF VAR NUMBER RETURN NUMBER IF VAR BIN_OP VAR NUMBER VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | N, K = list(map(int, input().strip().split(" ")))
A = list(map(int, input().strip().split(" ")))
A = sorted(A)
total = {}
for i in range(N):
if len(total) == 0:
if A[i] <= K:
total[A[i]] = 1
else:
L = len(total)
if A[i] <= K:
TT = {}
for x in total:
TT[x] = total[x]
for x in TT:
temp = x * A[i]
if temp <= K:
if temp in total:
total[temp] += TT[x]
else:
total[temp] = TT[x]
if A[i] in total:
total[A[i]] += 1
else:
total[A[i]] = 1
else:
break
SUM = 0
for x in total:
SUM += total[x]
print(SUM) | ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Read problems statements in mandarin chinese, russian and vietnamese as well.
Though our Head Chef retired from sport programming long back, but that did not affect his passion to contribute to the programming community. He still remains engaged by creating new problems and passing it on to the online judges. Last Night, he thought of a following problem for which he could not figure out a solution. You being his friend from the older days of programming decide to help him.
Find the number of non-empty subsequences in the given list of N integers such that the product of the values in the subsequences does not exceed K
------ Input ------
First line of the input will contain two space separated integers N and K. Next and last line of the input contains N space separated integers
------ Output ------
Print the answer to the given test case in a separate line.
------ Constraints ------
$1 ≤ N ≤ 30$
$1 ≤ K, A_{i} ≤ 10^{18}$
------ Subtasks ------
Subtask #1 : (30 points)
$1 ≤ N ≤ 10$
Subtask #2 : (70 points)
$1 ≤ N ≤ 30$
----- Sample Input 1 ------
3 4
1 2 3
----- Sample Output 1 ------
5
----- explanation 1 ------
For the given sample case, there are 7 non-empty subsequences out of which 2 have their product > 4. Those include {2, 3} and {1, 2, 3}. Hence, the answer is 7 - 2 = 5. | n, k = input().split()
n = int(n)
k = int(k)
l = [int(x) for x in input().split()]
d = dict()
for i in range(n):
if l[i] > k:
continue
copy = dict()
for key in d:
copy[key] = d[key]
for key in copy:
mult = key * l[i]
if mult <= k:
if not mult in copy:
d[mult] = copy[key]
else:
d[mult] = d[mult] + copy[key]
if not l[i] in d:
d[l[i]] = 1
else:
d[l[i]] = d[l[i]] + 1
sm = 0
for key in d:
sm = sm + d[key]
print(sm) | 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 ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Chef received an array A of N integers as a valentine's day present. He wants to maximize the length of the longest strictly increasing subsequence by choosing a subarray and adding a fixed integer X to all its elements.
More formally, Chef wants to maximize the length of the [longest strictly increasing subsequence] of A by performing the following operation at most once:
Pick 3 integers L, R and X \ (1 ≤ L ≤ R ≤ N, \ X \in \mathbb{Z}) and assign A_{i} := A_{i} + X \ \forall \ i \in [L, R].
Find the length of the longest strictly increasing sequence Chef can obtain after performing the operation at most once.
------ Input Format ------
- 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 one integer N, the size of the array.
- The next line contains N space-separated integers, where the i^{th} integer denotes A_{i}.
------ Output Format ------
For each test case, print a single line containing one integer ― the length of the longest strictly increasing sequence Chef can obtain.
------ Constraints ------
$1 ≤ T ≤ 10^{3}$
$1 ≤ N ≤ 2 \times 10^{5}$
$1 ≤ A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
1 2 1
5
1 5 8 6 9
4
1 2 2 1
----- Sample Output 1 ------
3
5
3
----- explanation 1 ------
Test case $1$: Chef can pick $(L,R,X)=(3,3,2)$. On performing the operation, $A$ becomes $[1,2,3]$. The LIS of the updated array has length $3$. The elements of the LIS are $[1,2,3]$.
Test case $2$: Chef can pick $(L,R,X)=(2,3,-3)$. On performing the operation, $A$ becomes $[1,2,5,6,9]$. The LIS of the updated array has length $5$. The elements of the LIS are $[1,2,5,6,9]$.
Test case $3$: Chef can pick $(L,R,X)=(4,4,4)$. On performing the operation, $A$ becomes $[1,2,2,5]$. The LIS of the updated array has length $3$. The elements of the LIS are $[1,2,5]$. | def subsequence(seq):
if not seq:
return []
answer = [1]
M = [None] * len(seq)
P = [None] * len(seq)
L = 1
M[0] = 0
for i in range(1, len(seq)):
lower = 0
upper = L
if seq[M[upper - 1]] < seq[i]:
j = upper
else:
while upper - lower > 1:
mid = (upper + lower) // 2
if seq[M[mid - 1]] < seq[i]:
lower = mid
else:
upper = mid
j = lower
P[i] = M[j - 1]
if j == L or seq[i] < seq[M[j]]:
M[j] = i
L = max(L, j + 1)
answer.append(L)
return answer
T = int(input())
for _ in range(T):
N = int(input())
a = list(map(int, input().split()))
left = subsequence(a)
a.reverse()
a = [(-x) for x in a]
right = subsequence(a)
M = 0
for i in range(N - 1):
if left[i] + right[N - 2 - i] > M:
M = left[i] + right[N - 2 - i]
print(M) | FUNC_DEF IF VAR RETURN LIST ASSIGN VAR LIST NUMBER ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NONE FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Chef received an array A of N integers as a valentine's day present. He wants to maximize the length of the longest strictly increasing subsequence by choosing a subarray and adding a fixed integer X to all its elements.
More formally, Chef wants to maximize the length of the [longest strictly increasing subsequence] of A by performing the following operation at most once:
Pick 3 integers L, R and X \ (1 ≤ L ≤ R ≤ N, \ X \in \mathbb{Z}) and assign A_{i} := A_{i} + X \ \forall \ i \in [L, R].
Find the length of the longest strictly increasing sequence Chef can obtain after performing the operation at most once.
------ Input Format ------
- 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 one integer N, the size of the array.
- The next line contains N space-separated integers, where the i^{th} integer denotes A_{i}.
------ Output Format ------
For each test case, print a single line containing one integer ― the length of the longest strictly increasing sequence Chef can obtain.
------ Constraints ------
$1 ≤ T ≤ 10^{3}$
$1 ≤ N ≤ 2 \times 10^{5}$
$1 ≤ A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
3
3
1 2 1
5
1 5 8 6 9
4
1 2 2 1
----- Sample Output 1 ------
3
5
3
----- explanation 1 ------
Test case $1$: Chef can pick $(L,R,X)=(3,3,2)$. On performing the operation, $A$ becomes $[1,2,3]$. The LIS of the updated array has length $3$. The elements of the LIS are $[1,2,3]$.
Test case $2$: Chef can pick $(L,R,X)=(2,3,-3)$. On performing the operation, $A$ becomes $[1,2,5,6,9]$. The LIS of the updated array has length $5$. The elements of the LIS are $[1,2,5,6,9]$.
Test case $3$: Chef can pick $(L,R,X)=(4,4,4)$. On performing the operation, $A$ becomes $[1,2,2,5]$. The LIS of the updated array has length $3$. The elements of the LIS are $[1,2,5]$. | def lis_right_dp(nums):
n = len(nums)
maxv = [0] * (n + 1)
pr, maxv[1] = 1, nums[-1]
dp = [0] * n
dp[-1] = 1
for j in range(n - 2, -1, -1):
l, r = 1, pr
while r - l > 2:
m = (r + l) // 2
if nums[j] >= maxv[m]:
r = m - 1
else:
l = m
x = 1
for p in range(r, l - 1, -1):
if maxv[p] > nums[j]:
x = p + 1
break
maxv[x] = max(maxv[x], nums[j])
dp[j] = x
pr = max(pr, x)
return dp
def lis_left_dp(nums):
n = len(nums)
minv = [1000000000.0] * (n + 1)
pr, minv[1] = 1, nums[0]
dp = [0] * n
dp[0] = 1
for j in range(1, n):
l, r = 1, pr
while r - l > 2:
m = (r + l) // 2
if nums[j] < minv[m]:
r = m - 1
else:
l = m
x = 1
for p in range(r, l - 1, -1):
if minv[p] < nums[j]:
x = p + 1
break
minv[x] = min(minv[x], nums[j])
dp[j] = x
pr = max(pr, x)
return dp
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
b = [(-x) for x in a][::-1]
g, h = lis_left_dp(a), lis_right_dp(a)
for j in range(n - 2, -1, -1):
h[j] = max(h[j], h[j + 1])
p, v = max(g), g[0]
for j in range(n - 1):
v = max(g[j], v)
p = max(p, v + h[j + 1])
print(p) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | moves = [
[
(1, 24),
(3, 22),
(5, 1),
(7, 3),
(9, 5),
(11, 7),
(24, 9),
(22, 11),
(14, 13),
(13, 15),
(15, 16),
(16, 13),
],
[
(14, 4),
(16, 3),
(9, 14),
(10, 16),
(19, 9),
(17, 10),
(3, 17),
(4, 19),
(5, 6),
(6, 8),
(8, 7),
(7, 5),
],
[
(5, 13),
(6, 14),
(17, 5),
(18, 6),
(21, 17),
(22, 18),
(14, 22),
(13, 21),
(1, 2),
(2, 4),
(4, 3),
(3, 1),
],
]
moves_len = len(moves)
for i in range(moves_len):
moves.append([])
for t in range(len(moves[i])):
moves[-1].append((moves[i][t][1], moves[i][t][0]))
colors = input().split()
def is_solved(col):
for s in range(6):
for i in range(s * 4 + 1, s * 4 + 4):
if col[i] != col[s * 4]:
return False
return True
def check_move(col, move):
col_temp = colors[:]
for t in move:
col_temp[t[1] - 1] = colors[t[0] - 1]
return is_solved(col_temp)
solved = False
for m in moves:
solved = check_move(colors, m)
if solved:
break
print("YES" if solved else "NO") | ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR STRING STRING |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | A1 = [
[0, 2, 4, 6, 8, 10, 21, 23],
[1, 3, 5, 7, 9, 11, 20, 22],
[2, 3, 16, 18, 9, 8, 15, 13],
[0, 1, 17, 19, 11, 10, 14, 12],
[12, 13, 4, 5, 16, 17, 20, 21],
[14, 15, 6, 7, 18, 19, 22, 23],
]
flag = False
B = list(map(int, input().split()))
for j in range(6):
A = list(B)
for i in range(2):
b = A[A1[j][0]]
A[A1[j][0]] = A[A1[j][1]]
A[A1[j][1]] = A[A1[j][2]]
A[A1[j][2]] = A[A1[j][3]]
A[A1[j][3]] = A[A1[j][4]]
A[A1[j][4]] = A[A1[j][5]]
A[A1[j][5]] = A[A1[j][6]]
A[A1[j][6]] = A[A1[j][7]]
A[A1[j][7]] = b
if (
(A[0] == A[1] == A[2] == A[3])
& (A[4] == A[5] == A[6] == A[7])
& (A[8] == A[9] == A[10] == A[11])
& (A[12] == A[13] == A[14] == A[15])
& (A[16] == A[17] == A[18] == A[19])
& (A[20] == A[21] == A[22] == A[23])
):
flag = True
break
A = list(B)
for i in range(2):
b = A[A1[j][7]]
A[A1[j][7]] = A[A1[j][6]]
A[A1[j][6]] = A[A1[j][5]]
A[A1[j][5]] = A[A1[j][4]]
A[A1[j][4]] = A[A1[j][3]]
A[A1[j][3]] = A[A1[j][2]]
A[A1[j][2]] = A[A1[j][1]]
A[A1[j][1]] = A[A1[j][0]]
A[A1[j][0]] = b
if (
(A[0] == A[1] == A[2] == A[3])
& (A[4] == A[5] == A[6] == A[7])
& (A[8] == A[9] == A[10] == A[11])
& (A[12] == A[13] == A[14] == A[15])
& (A[16] == A[17] == A[18] == A[19])
& (A[20] == A[21] == A[22] == A[23])
):
flag = True
break
if flag:
break
if flag:
print("YES")
else:
print("NO") | ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR IF BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | cube = [
[13, 14, 5, 6, 17, 18, 21, 22],
[14, 16, 9, 10, 19, 17, 4, 3],
[1, 3, 5, 7, 9, 11, 24, 22],
]
def rotate(seq, i):
lst = []
s = seq[:]
for x in range(8):
lst.append(s[cube[i][x] - 1])
for j in range(3):
lst = lst[2:] + lst[:2]
for x in range(8):
s[cube[i][x] - 1] = lst[x]
if check(s) and j % 2 == 0:
return True
return False
def check(seq):
for j in range(6):
if len(set(seq[j * 4 : j * 4 + 4])) != 1:
return False
return True
seq = list(map(int, input().split()))
for k in range(len(cube)):
if rotate(seq, k):
print("yes")
break
else:
print("no") | ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR LIST ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | qube = list(map(int, input().split()))
g = 1
change = {}
kostka1 = [1, 2, 1, 2, 3, 1, 3, 1, 4, 3, 4, 3, 5, 5, 5, 5, 6, 6, 6, 6, 4, 2, 4, 2]
kostka2 = [1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 4, 1, 4, 1, 5, 2, 5, 2, 6, 6, 6, 6]
kostka3 = [1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 2, 2, 3, 3, 6, 6, 6, 6, 5, 5]
kostka4 = [1, 1, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4, 3, 3, 5, 5, 6, 6, 2, 2, 5, 5, 6, 6]
kostka5 = [1, 1, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 2, 5, 2, 5, 1, 4, 1, 4, 6, 6, 6, 6]
kostka6 = [1, 2, 1, 2, 2, 3, 2, 3, 3, 4, 3, 4, 5, 5, 5, 5, 6, 6, 6, 6, 1, 4, 1, 4]
for i in range(len(qube)):
if qube[i] not in change:
j = qube[i]
change[j] = change.get(j, g)
g += 1
qube[i] = change[qube[i]]
if (
qube == kostka1
or qube == kostka2
or qube == kostka3
or qube == kostka4
or qube == kostka5
or qube == kostka6
):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR DICT ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | from itertools import groupby
def isSolved(c):
cons = [x[0] for x in groupby(c)]
return len(cons) == 6
color = list(map(int, input().strip().split()))
faces = [
[2, 4, 6, 8, 10, 12, 23, 21],
[13, 14, 5, 6, 17, 18, 21, 22],
[15, 16, 7, 8, 19, 20, 23, 24],
[1, 3, 5, 7, 9, 11, 24, 22],
[9, 10, 19, 17, 4, 3, 14, 16],
[1, 2, 18, 20, 12, 11, 15, 13],
]
def rotate(g, face):
c = g[:]
temp1 = c[face[0] - 1]
temp2 = c[face[1] - 1]
for i in range(0, 6, 2):
c[face[i] - 1] = c[face[i + 2] - 1]
c[face[i + 1] - 1] = c[face[i + 3] - 1]
c[face[-2] - 1] = temp1
c[face[-1] - 1] = temp2
return c
def canSolve(c):
for i in faces:
rot = rotate(c, i)
if isSolved(rot):
return True
x = list(reversed(i))
rot2 = rotate(c, x)
if isSolved(rot2):
return True
return False
if canSolve(color):
print("YES")
else:
print("NO") | FUNC_DEF ASSIGN VAR VAR NUMBER VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR RETURN VAR FUNC_DEF FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR RETURN NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | def f(a, d):
newa = a[:]
for i in range(24):
if i + 1 in d:
newa[d[i + 1] - 1] = a[i]
for i in range(0, 22, 4):
if not newa[i] == newa[i + 1] == newa[i + 2] == newa[i + 3]:
return False
return True
arr = list(map(int, input().split()))
var = [dict() for i in range(10)]
var[0][2] = 6
var[0][4] = 8
var[0][6] = 10
var[0][8] = 12
var[0][10] = 23
var[0][12] = 21
var[0][23] = 2
var[0][21] = 4
var[0][17] = 19
var[0][19] = 20
var[0][20] = 18
var[0][18] = 17
var[2][1] = 5
var[2][3] = 7
var[2][5] = 9
var[2][7] = 11
var[2][9] = 24
var[2][11] = 22
var[2][24] = 1
var[2][22] = 3
var[2][13] = 14
var[2][15] = 13
var[2][16] = 15
var[2][14] = 16
var[4][13] = 5
var[4][14] = 6
var[4][5] = 17
var[4][6] = 18
var[4][17] = 21
var[4][18] = 22
var[4][21] = 13
var[4][22] = 14
var[4][1] = 3
var[4][3] = 4
var[4][4] = 2
var[4][2] = 1
var[6][15] = 7
var[6][16] = 8
var[6][7] = 19
var[6][8] = 20
var[6][19] = 23
var[6][20] = 24
var[6][23] = 15
var[6][24] = 16
var[6][9] = 10
var[6][10] = 12
var[6][12] = 11
var[6][11] = 9
var[8][3] = 17
var[8][4] = 19
var[8][17] = 10
var[8][19] = 9
var[8][10] = 16
var[8][9] = 14
var[8][16] = 3
var[8][14] = 4
var[8][5] = 6
var[8][6] = 8
var[8][7] = 5
var[8][8] = 7
for i in range(0, 9, 2):
for j in range(1, 25):
if j in var[i]:
var[i + 1][var[i][j]] = j
for i in range(10):
if f(arr, var[i]):
print("YES")
exit()
print("NO") | FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | cb = [int(item) for item in input().split()]
cbb = [cb[i : i + 4] for i in range(0, 24, 4)]
cons = [([i] * 4) for i in range(1, 7)]
k = 0
completeFaces = []
def v(x, y):
return cb[x - 1] == cb[y - 1]
def rot(thing):
for p, xx in enumerate(thing):
x = [xx[:2], xx[2:]]
for i in range(2):
for j in range(i + 1, 2):
x[i][j], x[j][i] = x[j][i], x[i][j]
if p != 5:
x[0][0], x[1][0] = x[1][0], x[0][0]
x[0][1], x[1][1] = x[1][1], x[0][1]
else:
x[0] = x[0][::-1]
x[1] = x[1][::-1]
thing[p] = x[0] + x[1]
return thing
for i in range(0, 24, 4):
if cb[i : i + 4] in cons:
k += 1
completeFaces.append(i // 4 + 1)
if k != 2 or completeFaces not in [[1, 3], [4, 5], [2, 6]]:
print("NO")
else:
if completeFaces == [1, 3]:
cbb[0], cbb[2], cbb[3], cbb[4] = (
cbb[4].copy(),
cbb[3].copy(),
cbb[0].copy(),
cbb[2].copy(),
)
cbb = rot(cbb)
elif completeFaces == [2, 6]:
cbb[1], cbb[3], cbb[4], cbb[5] = (
cbb[4].copy(),
cbb[1].copy(),
cbb[5].copy(),
cbb[3].copy(),
)
cbb[0] = [cbb[0][2], cbb[0][0], cbb[0][3], cbb[0][1]]
cbb[2] = [cbb[2][1], cbb[2][3], cbb[2][0], cbb[2][2]]
cb = cbb[0] + cbb[1] + cbb[2] + cbb[3] + cbb[4] + cbb[5]
case1 = (
v(5, 10)
and v(7, 12)
and v(1, 6)
and v(3, 8)
and v(2, 22)
and v(4, 24)
and v(9, 21)
and v(11, 23)
and v(5, 7)
and v(10, 12)
and v(1, 3)
and v(6, 8)
and v(2, 4)
and v(22, 24)
and v(9, 11)
and v(21, 23)
)
case2 = (
v(5, 2)
and v(7, 4)
and v(9, 6)
and v(11, 8)
and v(1, 21)
and v(3, 23)
and v(10, 22)
and v(12, 24)
and v(5, 7)
and v(2, 4)
and v(9, 11)
and v(6, 8)
and v(1, 3)
and v(21, 23)
and v(10, 12)
and v(22, 24)
)
if case1 or case2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR NUMBER VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF RETURN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_DEF FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR LIST NUMBER NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER LIST VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR NUMBER LIST VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER FUNC_CALL VAR NUMBER NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
During the breaks between competitions, top-model Izabella tries to develop herself and not to be bored. For example, now she tries to solve Rubik's cube 2x2x2.
It's too hard to learn to solve Rubik's cube instantly, so she learns to understand if it's possible to solve the cube in some state using 90-degrees rotation of one face of the cube in any direction.
To check her answers she wants to use a program which will for some state of cube tell if it's possible to solve it using one rotation, described above.
Cube is called solved if for each face of cube all squares on it has the same color.
https://en.wikipedia.org/wiki/Rubik's_Cube
-----Input-----
In first line given a sequence of 24 integers a_{i} (1 ≤ a_{i} ≤ 6), where a_{i} denotes color of i-th square. There are exactly 4 occurrences of all colors in this sequence.
-----Output-----
Print «YES» (without quotes) if it's possible to solve cube using one rotation and «NO» (without quotes) otherwise.
-----Examples-----
Input
2 5 4 6 1 3 6 2 5 5 1 2 3 5 3 1 1 2 4 6 6 4 3 4
Output
NO
Input
5 3 5 3 2 5 2 5 6 2 6 2 4 4 4 4 1 1 1 1 6 3 6 3
Output
YES
-----Note-----
In first test case cube looks like this: [Image]
In second test case cube looks like this: [Image]
It's possible to solve cube by rotating face with squares with numbers 13, 14, 15, 16. | import sys
def check(q):
if (
q[1] == q[2] == q[3] == q[4]
and q[5] == q[6] == q[7] == q[8]
and q[9] == q[10] == q[11] == q[12]
and q[13] == q[14] == q[15] == q[16]
and q[17] == q[18] == q[19] == q[20]
and q[21] == q[22] == q[23] == q[24]
):
return True
else:
return False
a = [0] + [int(x) for x in input().split()]
swaps = []
b = a[:]
b[17] = a[3]
b[19] = a[4]
b[10] = a[17]
b[9] = a[19]
b[14] = a[9]
b[16] = a[10]
b[4] = a[14]
b[3] = a[16]
if check(b):
print("YES")
return
b = a[:]
b[17] = a[10]
b[19] = a[9]
b[10] = a[16]
b[9] = a[14]
b[14] = a[4]
b[16] = a[3]
b[4] = a[19]
b[3] = a[17]
if check(b):
print("YES")
return
b = a[:]
b[13] = a[21]
b[14] = a[22]
b[5] = a[13]
b[6] = a[14]
b[17] = a[5]
b[18] = a[6]
b[21] = a[17]
b[22] = a[18]
if check(b):
print("YES")
return
b = a[:]
b[21] = a[13]
b[22] = a[14]
b[13] = a[5]
b[14] = a[6]
b[5] = a[17]
b[6] = a[18]
b[17] = a[21]
b[18] = a[22]
if check(b):
print("YES")
return
b = a[:]
b[7] = a[19]
b[8] = a[20]
b[19] = a[23]
b[20] = a[24]
b[23] = a[15]
b[24] = a[16]
b[15] = a[7]
b[16] = a[8]
if check(b):
print("YES")
return
b = a[:]
b[19] = a[7]
b[20] = a[8]
b[23] = a[19]
b[24] = a[20]
b[15] = a[23]
b[16] = a[24]
b[7] = a[15]
b[8] = a[16]
if check(b):
print("YES")
return
b = a[:]
b[1] = a[5]
b[3] = a[7]
b[5] = a[9]
b[7] = a[11]
b[9] = a[22]
b[11] = a[24]
b[22] = a[1]
b[24] = a[3]
if check(b):
print("YES")
return
b = a[:]
b[5] = a[1]
b[7] = a[3]
b[9] = a[5]
b[11] = a[7]
b[22] = a[9]
b[24] = a[11]
b[1] = a[22]
b[3] = a[24]
if check(b):
print("YES")
return
b = a[:]
b[10] = a[6]
b[12] = a[8]
b[6] = a[2]
b[8] = a[4]
b[2] = a[23]
b[4] = a[21]
b[23] = a[10]
b[21] = a[12]
if check(b):
print("YES")
return
b = a[:]
b[6] = a[10]
b[8] = a[12]
b[2] = a[6]
b[4] = a[8]
b[23] = a[2]
b[21] = a[4]
b[10] = a[23]
b[12] = a[21]
if check(b):
print("YES")
return
b = a[:]
b[1] = a[18]
b[2] = a[20]
b[18] = a[12]
b[20] = a[11]
b[12] = a[15]
b[11] = a[13]
b[15] = a[1]
b[13] = a[2]
if check(b):
print("YES")
return
b = a[:]
b[18] = a[1]
b[20] = a[2]
b[12] = a[18]
b[11] = a[20]
b[15] = a[12]
b[13] = a[11]
b[1] = a[15]
b[2] = a[13]
if check(b):
print("YES")
return
print("NO") | IMPORT FUNC_DEF IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.