description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
ans = []
for _ in range(int(input())):
n, k = map(int, input().split())
otv = []
if k != n - 1:
otv.append([k, n - 1])
if k != 0:
otv.append([n - k - 1, 0])
i = 1
while i < n - i - 1:
if i != k and i != n - k - 1 and n - i - 1 != k and n - i - 1 != n - k - 1:
otv.append([i, n - i - 1])
i += 1
elif n == 4:
otv.append([-1])
else:
otv.append([n - 1, n - 2])
otv.append([1, 3])
otv.append([2, n - 3])
otv.append([0, n - 4])
i = 4
while i < n - i - 1:
otv.append([i, n - i - 1])
i += 1
ans.append(otv)
for i in range(len(ans)):
for j in range(len(ans[i])):
if len(ans[i][j]) == 1:
print(ans[i][j][0])
else:
print(ans[i][j][0], ans[i][j][1])
|
ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
def func():
n, k = map(int, input().split())
a = [(0) for i in range(n // 2)]
b = [(0) for i in range(n // 2)]
if k == 0:
for i in range(n // 2):
a[i], b[i] = i, i ^ n - 1
elif k > 0 and k < n - 1:
itr = min(k, k ^ n - 1)
for i in range(n // 2):
if i != 0 or i != itr:
a[i], b[i] = i, i ^ n - 1
a[0], b[0] = 0, k ^ n - 1
a[itr], b[itr] = k, n - 1
else:
if n == 4:
print(-1)
return
a[0], b[0] = n - 2, n - 1
a[1], b[1] = 1, n - 3
a[2], b[2] = 0, 2
for i in range(3, n // 2):
a[i], b[i] = i, i ^ n - 1
for i in range(n // 2):
print(a[i], b[i])
t = int(input())
for i in range(t):
func()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
for t in range(int(input())):
n, k = map(int, input().split())
if k == n - 1 and n == 4:
print(-1)
continue
used = set()
if k == n - 1:
for i in range(n - 1):
if i in used:
continue
if i == 0:
print(i, n - 1 - 3)
used.add(n - 1 - 3)
elif i == 1:
print(i, 3)
used.add(3)
elif i == n - 2:
print(n - 1, n - 2)
used.add(n - 2)
else:
print(i, n - 1 - i)
used.add(n - 1 - i)
else:
for i in range(n):
if i in used:
continue
if i == 0:
print(i, n - 1 - k)
used.add(n - 1 - k)
elif i == k:
print(i, n - 1)
used.add(n - 1)
else:
print(i, n - 1 - i)
used.add(n - 1 - i)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
import sys
input = sys.stdin.readline
t = int(input().strip())
def comp(x, n):
return n - 1 ^ x
for _ in range(t):
n, k = map(int, input().split())
if k == 0:
for i in range(n // 2):
print(i, comp(i, n))
elif k < n - 1:
print(k, n - 1)
print(0, comp(k, n))
for i in range(n // 2):
if i != 0 and i != comp(k, n) and i != k:
print(i, comp(i, n))
elif n > 4:
print(n - 1, n - 2)
print(0, 2)
print(1, n - 3)
for i in range(n // 2):
if i != 0 and i != 1 and i != 2:
print(i, comp(i, n))
else:
print(-1)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
def c(n, i):
return n - i - 1
def solve(n, k):
if k == 0:
for i in range(n // 2):
print(i, c(n, i))
elif k < n - 1:
ignore = [0, k, c(n, k), n - 1]
print(0, c(n, k))
print(k, n - 1)
for i in range(n // 2):
if i in ignore:
continue
print(i, c(n, i))
elif n == 4:
print(-1)
else:
print(0, 2)
print(1, n - 3)
print(n - 1, n - 2)
for i in range(3, n // 2):
print(i, c(n, i))
for case in range(int(input())):
n, k = map(int, input().split())
solve(n, k)
|
FUNC_DEF RETURN BIN_OP BIN_OP VAR VAR NUMBER FUNC_DEF IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR LIST NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
tc = int(input())
for t in range(tc):
n, k = map(int, input().split())
if n == 4 and k == 3:
print(-1)
elif n == 2:
if k == 0:
print("0 1")
else:
print(-1)
else:
nums = list()
for i in range(n // 2):
nums.append([0, 0])
for i in range(n // 2):
nums[i][0] = n - 1 - i
nums[i][1] = i
if k > 0:
a = 0
if k < n // 2:
nums[0][1] = nums[k][1]
nums[k][1] = 0
else:
l = n - k - 1
if k == n - 1:
l = n - (n - 2) - 1
nums[0][1] = nums[l][0]
nums[l][0] = 0
if k == n - 1:
l = n // 2 - 1
nums[1][0] = nums[l][1]
nums[l][1] = 0
for pair in nums:
print("{} {}".format(pair[0], pair[1]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
import sys
for _ in range(int(sys.stdin.readline())):
n, k = map(int, sys.stdin.readline().split())
if k > n * (n - 2) / 4:
print(-1)
else:
if k != 0 and k != n - 1:
print(k, n - 1)
print(0, k ^ n - 1)
elif k == 0:
print(0, n - 1)
else:
print(n - 1, n - 2)
print(3, 1)
print(0, n - 1 ^ 3)
for i in range(1, n // 2):
if i == k or i == k ^ n - 1:
continue
elif k == n - 1:
if i in [1, 3]:
continue
else:
print(i, i ^ n - 1)
else:
print(i, i ^ n - 1)
|
IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER IF VAR LIST NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
for _ in range(int(input())):
n, m = map(int, input().split())
arr = [i for i in range(n)]
if n == 4 and m == 3:
print(-1)
continue
if n == m + 1:
arr[0], arr[m - 1] = arr[m - 1], arr[0]
arr[1], arr[n - 4] = arr[n - 4], arr[1]
else:
arr[0], arr[m] = arr[m], arr[0]
for i in range(n // 2):
print(arr[i], arr[n - 1 - i])
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
cases = int(input())
for _ in range(cases):
n, k = map(int, input().split())
if k == 0:
for i in range(n // 2):
print("%d %d" % (i, n - 1 ^ i))
elif k == n - 1:
if n == 4:
print("-1")
else:
print("%d %d" % (n - 1, n - 2))
print("1 %d" % (n - 3))
print("0 2")
for i in range(3, n // 2):
print("%d %d" % (i, i ^ n - 1))
else:
print("%d %d" % (k, n - 1))
print("%d %d" % (0, k ^ n - 1))
for i in range(1, n // 2):
if i != k and i != k ^ n - 1:
print("%d %d" % (i, i ^ n - 1))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING NUMBER BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR BIN_OP VAR BIN_OP VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
test_cases = int(input())
for _ in range(test_cases):
a = list(map(int, input().split()))
n = a[0]
k = a[1]
if n == 4 and k == 3:
print(-1)
elif k == 0:
for i in range(0, n // 2):
print(f"{i} {n - i - 1}")
elif k < n - 1:
print(f"{n - 1} {k}")
print(f"{n - k - 1} 0")
for i in range(1, n // 2):
if i != k and i != n - k - 1:
print(f"{i} {n - i - 1}")
elif k == n - 1:
print(f"{n - 1} {n - 2}")
print(f"0 2")
print(f"1 {n - 3}")
for i in range(3, n // 2):
print(f"{i} {n - i - 1}")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR STRING BIN_OP BIN_OP VAR VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
T = int(input())
for t in range(T):
n, k = list(map(int, input().split()))
if k == n - 1:
if n == 4:
print(-1)
else:
print(n - 2, n - 1)
print(1, 3)
print(0, n - 4)
a, b = 2, n - 3
for i in range(n // 2 - 2):
if a != 3:
print(a, b)
a += 1
b -= 1
continue
if k == 0:
a, b = 0, n - 1
for i in range(n // 2):
print(a, b)
a += 1
b -= 1
continue
print(k, n - 1)
print(0, n - k - 1)
a, b = 1, n - 2
for i in range(n // 2 - 1):
if a != k and b != k:
print(a, b)
a += 1
b -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
def swap_partners(a, b, l):
a_index = -1
b_index = -1
for i, pair in enumerate(l):
if a in pair:
a_index = i
if b in pair:
b_index = i
if l[a_index][0] != a:
l[a_index] = l[a_index][::-1]
if l[b_index][0] != b:
l[b_index] = l[b_index][::-1]
l[b_index][0] = l[a_index][1]
l[a_index][1] = b
for _ in range(int(input())):
n, k = list(map(int, input().split()))
if k == n - 1 and n <= 4:
print(-1)
continue
pairs = []
l = 0
r = n - 1
while l < r:
pairs.append([l, r])
l += 1
r -= 1
if k < n - 1:
swap_partners(k, n - 1, pairs)
for pair in pairs:
print(pair[0], pair[1])
elif k == n - 1:
swap_partners(k - 1, n - 1, pairs)
swap_partners(1, 3, pairs)
for pair in pairs:
print(pair[0], pair[1])
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER NUMBER VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
import sys
ip = sys.stdin.readline
for _ in range(int(ip())):
n, k = map(int, ip().split())
vis = [(False) for _ in range(n)]
ans = []
if n - 1 == k:
if n - 1 == 3:
print(-1)
else:
vis[n - 2] = vis[n - 1] = True
ans.append((n - 2, n - 1))
vis[1] = vis[3] = True
ans.append((1, 3))
vis[n - 1 - 3] = vis[0] = True
ans.append((n - 1 - 3, 0))
for i in range(n - 3, 1, -1):
if not vis[i]:
vis[i] = True
vis[n - 1 - i] = True
ans.append((i, n - 1 - i))
for i in range(n // 2):
print(ans[i][0], ans[i][1])
else:
vis[n - 1] = vis[k] = vis[n - 1 - k] = vis[0] = True
ans.append((n - 1, k))
if k != 0:
ans.append((n - 1 - k, 0))
for i in range(n - 2, 0, -1):
if not vis[i]:
vis[i] = True
vis[n - 1 - i] = True
ans.append((i, n - 1 - i))
for i in range(n // 2):
print(ans[i][0], ans[i][1])
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
def solve():
n, k = map(int, input().split())
res = 0
if n == 4 and k == 3:
print(-1)
return
pool = set([i for i in range(n)])
pairs = []
if k < n - 1:
pairs.append((k, n - 1))
print(k, n - 1)
res += k & n - 1
pool.remove(k)
pool.remove(n - 1)
else:
pairs.append([k - 1, k])
pairs.append([1, k - 2])
res += k - 1 & k
res += 1 & k - 2
print(k - 1, k)
print(1, k - 2)
pool.remove(k)
pool.remove(k - 1)
pool.remove(1)
pool.remove(k - 2)
for i in range(n // 2):
if i in pool and n - i - 1 in pool:
pairs.append([i, n - i - 1])
print(i, n - i - 1)
res += i & n - i - 1
pool.remove(i)
pool.remove(n - i - 1)
if len(pool) == 2:
pairs.append(list(pool))
print(*list(pool))
res += list(pool)[0] & list(pool)[1]
for _ in range(int(input())):
solve()
|
FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER RETURN ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST NUMBER BIN_OP VAR NUMBER VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR LIST VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
def find_pairs(n, k):
if n == 2:
if k == 1:
print(0, 1)
else:
print(-1)
elif k == 0:
for i in range(n // 2):
print(i, n - i - 1)
elif n == 4 and k == 3:
print(-1)
elif k != n - 1:
print(k, n - 1)
print(0, n - k - 1)
for i in range(1, n // 2):
if i != k and i != n - k - 1:
print(i, n - i - 1)
else:
print(n - 1, n - 2)
print(1, n // 2 - 1)
print(0, n // 2)
for i in range(2, n // 2 - 1):
print(i, n - i - 1)
T = int(input())
for t in range(T):
n, k = [int(j) for j in input().split()]
find_pairs(n, k)
|
FUNC_DEF IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once.
Find $\frac{n}{2}$ pairs of elements such that:
Each element in the set is in exactly one pair.
The sum over all pairs of the bitwise AND of its elements must be exactly equal to $k$. Formally, if $a_i$ and $b_i$ are the elements of the $i$-th pair, then the following must hold: $$\sum_{i=1}^{n/2}{a_i \& b_i} = k,$$ where $\&$ denotes the bitwise AND operation.
If there are many solutions, print any of them, if there is no solution, print $-1$ instead.
-----Input-----
The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 400$) β the number of test cases. Description of the test cases follows.
Each test case consists of a single line with two integers $n$ and $k$ ($4 \leq n \leq 2^{16}$, $n$ is a power of $2$, $0 \leq k \leq n-1$).
The sum of $n$ over all test cases does not exceed $2^{16}$. All test cases in each individual input will be pairwise different.
-----Output-----
For each test case, if there is no solution, print a single line with the integer $-1$.
Otherwise, print $\frac{n}{2}$ lines, the $i$-th of them must contain $a_i$ and $b_i$, the elements in the $i$-th pair.
If there are many solutions, print any of them. Print the pairs and the elements in the pairs in any order.
-----Examples-----
Input
4
4 0
4 1
4 2
4 3
Output
0 3
1 2
0 2
1 3
0 1
2 3
-1
-----Note-----
In the first test, $(0\&3)+(1\&2) = 0$.
In the second test, $(0\&2)+(1\&3) = 1$.
In the third test, $(0\&1)+(2\&3) = 2$.
In the fourth test, there is no solution.
|
t = int(input())
while t != 0:
n, summ = [int(x) for x in input().split()]
if summ == n - 1:
if summ == 3:
print(-1)
else:
print(n - 2, n - 1)
print(1, n - 3)
print(0, 2)
l = 3
while l < n // 2:
if l != summ and l != n - 1 - summ:
print(l, n - 1 - l)
l += 1
else:
print(summ, n - 1)
if summ != 0:
print(0, n - 1 - summ)
l = 1
while l < n // 2:
if l != summ and l != n - 1 - summ:
print(l, n - 1 - l)
l += 1
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def length(n):
i = 0
while n >= pow(2, i):
i += 1
return i
def minmax(a):
c = []
for i in range(len(a)):
if not i:
c.append([a[i]])
elif length(a[i]) == length(a[i - 1]):
c[-1].append(a[i])
else:
c.append([a[i]])
if len(c) == 1:
a = [(temp - pow(2, length(c[0][0]) - 1)) for temp in c[0]]
return minmax(a)
else:
ans = c[-1][0] ^ c[0][0]
for i in c[-1]:
for j in c[:-1]:
for k in j:
ans = min(ans, i ^ k)
return ans
n = int(input().strip())
a = [int(t) for t in input().strip().split(" ")]
a.sort()
if a[-1] == 0:
print(0)
else:
print(minmax(a))
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR EXPR FUNC_CALL VAR LIST VAR VAR IF FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER VAR VAR NUMBER RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER NUMBER FOR VAR VAR NUMBER FOR VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
from itertools import *
int(input())
a = sorted(list(map(int, input().split())))
if a[0] == a[-1]:
print(0)
else:
k = 30
while not (a[0] ^ a[-1]) >> k & 1:
k -= 1
print(
min(
i ^ j
for i, j in product(
[i for i in a if i >> k & 1], [i for i in a if not i >> k & 1]
)
)
)
|
EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
input()
numlist = [int(num) for num in input().split()]
big, small = numlist[0], numlist[0]
for num in numlist:
big = max(num, big)
small = min(num, small)
dist = big ^ small
k = len("{0:b}".format(dist))
split = big >> k - 1 << k - 1
bignums = []
smallnums = []
for num in numlist:
if num >= split:
bignums.append(num)
else:
smallnums.append(num)
for num in bignums:
for othernum in smallnums:
dist = min(dist, num ^ othernum)
print(dist)
|
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def bitize(n, bits=32):
max_bit = -1
L = [(0) for i in range(0, bits)]
if n == 0:
return [L, -1]
for i in range(0, bits):
if n == 0 and max_bit == -1:
max_bit = i - 1
L[i] = n % 2
n //= 2
return [L, max_bit]
def find_min_max(A):
BA = [bitize(a) for a in A]
max_bit = -1
for i in range(0, len(BA)):
if BA[i][1] > max_bit:
max_bit = BA[i][1]
max_list = []
less_list = []
top_A = []
if max_bit == -1:
return 0
for j in range(0, len(BA)):
if BA[j][1] < max_bit:
less_list.append(A[j])
elif BA[j][1] == max_bit:
max_list.append(A[j])
top_A.append(A[j] ^ pow(2, max_bit))
min_val = pow(2, 32)
if len(max_list) > 0 and len(less_list) > 0:
for i in range(0, len(max_list)):
for j in range(0, len(less_list)):
if min_val > max_list[i] ^ less_list[j]:
min_val = max_list[i] ^ less_list[j]
return min_val
elif len(less_list) == 0:
counts = [(0) for i in range(0, len(top_A))]
if len(max_list) % 2 == 0:
for i in range(0, len(top_A)):
top_A[i] += pow(2, max_index)
counts[i] = find_min_max(top_A)
top_A[i] -= pow(2, max_index)
return min(counts)
else:
return find_min_max(top_A)
return min_val
n = int(input())
A = [int(a) for a in input().split()]
print(find_min_max(A))
|
FUNC_DEF NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER RETURN LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR NUMBER RETURN LIST VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR RETURN VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR NUMBER VAR RETURN FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def find_answer(bin_l):
while True:
len_set = set(map(lambda x: len(x), bin_l))
if len(len_set) > 1:
break
if 0 in len_set or bin_l[0][0] == "0":
return 0
bin_l = list(map(lambda x: bin(int(x[1:], 2)), bin_l))
max_len = max(map(lambda x: len(x), bin_l))
big_set = set(map(lambda x: int(x, 2), filter(lambda x: len(x) == max_len, bin_l)))
small_set = set(
map(lambda x: int(x, 2), filter(lambda x: len(x) != max_len, bin_l))
)
return min(
[(cur_big ^ cur_small) for cur_big in big_set for cur_small in small_set]
)
input()
l = list(map(int, input().split()))
bin_list = list(map(lambda x: bin(x)[2:], l))
print(find_answer(bin_list))
|
IMPORT FUNC_DEF WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER IF NUMBER VAR VAR NUMBER NUMBER STRING RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def solve(As):
a = max(As)
b = -1
while a > 0:
a >>= 1
b += 1
if b < 0:
return 0
l = 1 << b
while all(a & l for a in As):
l >>= 1
if l == 0:
return 0
Al = [a for a in As if not a & l]
Au = [a for a in As if a & l]
best = l << 1
for al in Al:
for au in Au:
if al ^ au < best:
best = al ^ au
return best
n = int(input())
As = set(map(int, input().split()))
print(solve(As))
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR WHILE FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = list(map(int, input().split()[:n]))
a.sort(reverse=True)
lens = []
for i in range(n):
lens.append(len(bin(a[i])[2:]))
mmlen = lens[0]
xor = 10**9
start = n
for i in range(len(a)):
if mmlen != lens[i]:
start = i
break
while start == n:
if mmlen == 1:
xor = 0
for i in range(n):
xor ^= a[i]
break
for i in range(n):
a[i] = a[i] ^ 2 ** (mmlen - 1)
lens[i] = len(bin(a[i])[2:])
mmlen = lens[0]
for i in range(len(a)):
if mmlen != lens[i]:
start = i
break
for i in range(n):
if lens[i] == mmlen:
for j in range(start, n):
xor = min(xor, a[i] ^ a[j])
else:
break
print(xor)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR WHILE VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import itertools as it
l = int(input())
arr = [int(num) for num in input().split(" ")]
arr = list(set(arr))
arr_tup = [(num, len(bin(num))) for num in arr]
max_bin = max(arr_tup, key=lambda x: x[1])[1]
set_big = {num[0] for num in arr_tup if num[1] == max_bin}
set_small = set(arr) - set_big
general_min = float("Inf")
if set_small:
for big in set_big:
for small in set_small:
if big ^ small < general_min:
general_min = big ^ small
elif len(set_big) == 1:
general_min = 0
else:
perms = it.permutations(set_big)
for perm in perms:
_max = 0
for index in range(len(perm) - 1):
xor = perm[index] ^ perm[index + 1]
if xor > _max:
_max = xor
if _max < general_min:
general_min = _max
print(general_min)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER VAR VAR VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = list(map(int, input().rstrip().split()))
if len(set(a)) == 1 and list(set(a))[0] == 0:
print(0)
else:
bitor = bitnot = 0
for number in a:
bitor |= number
bitnot |= ~number
i = bitor & bitnot
while i & i - 1:
i &= i - 1
xs = [number for number in a if number & i]
ys = [number for number in a if number & i == 0]
print(min(x ^ y for x in xs for y in ys))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
N = int(input())
v = list(map(int, input().split(" ")))
def findLeftOne(n):
h1 = 0
while n >> h1:
h1 += 1
return h1 - 1
biggest = []
shift = 0
eh = 0
while True:
for n in v:
if n & eh:
print(n)
n -= eh
shifted = n >> shift
if shifted:
if shifted > 1:
shift = findLeftOne(n)
biggest = []
biggest.append(n)
if len(biggest) == len(v):
mask = 1 << shift
v = list(map(lambda x: x ^ mask, v))
shift -= 1
else:
break
res = 1 << 64
for b in biggest:
for n in v:
if not n >> shift:
res = min(res, n ^ b)
if len(biggest):
print(res)
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def binary(a):
x = ""
while a > 0:
x = str(a % 2) + x
a //= 2
return x
def update(x):
x = x[1:]
i = 0
while i < len(x) and x[i] != "1":
i += 1
x = x[i:]
return x
n = int(input())
a = list(map(int, input().split()))
lengths = []
binary_a = {}
for i in range(len(a)):
x = binary(a[i])
if len(x) in binary_a:
binary_a[len(x)].append(a[i])
else:
binary_a[len(x)] = [a[i]]
lengths.append(len(x))
max_length = max(lengths)
min_xor = float("inf")
if max_length == 0:
print("0")
exit()
while len(binary_a) == 1:
lengths = []
for i in binary_a[max_length]:
x = update(binary(i))
if len(x) in binary_a:
binary_a[len(x)].append(i)
else:
binary_a[len(x)] = [i]
lengths.append(len(x))
binary_a.pop(max_length)
max_length = max(lengths)
for i in binary_a[max_length]:
for j in binary_a:
if j != max_length:
for k in binary_a[j]:
min_xor = min(min_xor, i ^ k)
print(min_xor)
|
FUNC_DEF ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR STRING VAR NUMBER ASSIGN VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR VAR FOR VAR VAR IF VAR VAR FOR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
from itertools import groupby, product
input()
alist = sorted(int(c) for c in input().strip().split(" "))
while True:
blens = set(a.bit_length() for a in alist)
if len(blens) > 1:
break
blen = blens.pop()
if blen > 1:
alist = [(a ^ 1 << blen - 1) for a in alist]
else:
print(0)
import sys
sys.exit(0)
keyfunc = lambda x: x.bit_length()
alist.sort(key=keyfunc)
aminlist = []
for k, v in groupby(alist, keyfunc):
if k == max(blens):
amaxlist = list(v)
else:
aminlist += list(v)
print(sorted(x ^ y for x, y in product(amaxlist, aminlist))[0])
|
IMPORT EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING WHILE NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR NUMBER IMPORT EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def find_interesting_power_of_2(a):
biggest = max(a)
res = 1
bits = 1
while res < biggest:
res = res * 2
bits += 1
counters = [0] * bits
for ai in a:
for p in range(bits):
if ai & 1 << p != 0:
counters[p] += 1
for p in reversed(range(bits)):
if counters[p] != 0 and counters[p] != len(a):
return p
return -1
n = int(input())
a = [int(x) for x in input().split(" ")]
interesting = find_interesting_power_of_2(a)
if interesting == -1:
print(0)
else:
left = [x for x in a if x & 1 << interesting > 0]
right = [x for x in a if x & 1 << interesting == 0]
final_result = -1
for l in left:
for r in right:
final_result = min(final_result, l ^ r) if final_result != -1 else l ^ r
print(final_result)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR FUNC_CALL VAR VAR RETURN VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input().strip())
arr = map(int, input().strip().split(" "))
smax = set(arr)
other = set()
while True:
it = smax.copy()
smax.clear()
blmax = -1
for a in it:
bl = a.bit_length()
if bl > blmax:
other |= smax
smax.clear()
smax.add(a)
blmax = bl
elif bl == blmax:
smax.add(a)
else:
other.add(a)
if len(other) == 0 and len(smax) > 1:
smax = set([(a ^ 1 << blmax - 1) for a in smax])
else:
break
if len(other) == 0:
print(0)
else:
ans = 4294967295
for a in smax:
for b in other:
t = a ^ b
if t < ans:
ans = t
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR WHILE NUMBER ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER BIN_OP VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
ns = [int(x) for x in input().split()]
res = 0
for x in ns:
for y in ns:
res = max(res, x ^ y)
bit = 1 << len(bin(res)[3:])
A = [x for x in ns if x & bit]
B = [x for x in ns if x & bit == 0]
for x in A:
for y in B:
res = min(res, x ^ y)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def anotherMinimaxProblem(a):
msb1 = []
msb0 = []
shifter = 32
allinone = 1
while allinone and shifter > 1:
shifter -= 1
msb1 = []
msb0 = []
for i in range(len(a)):
sh = a[i] >> shifter
if sh & 1 == 1:
msb1.append(a[i])
else:
msb0.append(a[i])
if len(msb1) != 0 and len(msb0) != 0:
allinone = 0
if len(msb1) == 0 or len(msb0) == 0:
return 0
mn = 2**32
for i in range(len(msb1)):
for j in range(len(msb0)):
mn = min(mn, msb1[i] ^ msb0[j])
return mn
n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
result = anotherMinimaxProblem(a)
print(result)
|
IMPORT FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def anotherMinimaxProblem(a):
a_min = min(a)
a_max = max(a)
if a_min == a_max:
return 0
a_min_bin = bin(a_min)
a_max_bin = bin(a_max)
if len(a_min_bin) < len(a_max_bin):
barrier = 2 ** (len(a_max_bin) - 3)
else:
for i in range(2, len(a_min_bin)):
if a_min_bin[i] != a_max_bin[i]:
barrier = int(a_max_bin[: i + 1] + "0" * (len(a_min_bin) - i - 1), 2)
break
lower = []
upper = []
for num in a:
if num < barrier:
lower.append(num)
else:
upper.append(num)
minimax = barrier * 2
for num1 in lower:
for num2 in upper:
current_xor = num1 ^ num2
if current_xor < minimax:
minimax = current_xor
return minimax
n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
result = anotherMinimaxProblem(a)
print(result)
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def trim(a):
to_trim = max_length
for number in a:
for i in range(max_length):
if number[i] == "0":
to_trim = min(to_trim, i)
break
a = list(map(lambda x: x[to_trim:], a))
return a
def enrich():
for i in range(len(a)):
a[i] = "0" * (max_length - len(a[i])) + a[i]
n = int(input())
a = list(map(lambda x: bin(int(x))[2:], input().strip().split(" ")))
max_length = max(map(len, a))
if max_length != min(map(len, a)):
enrich()
else:
a = trim(a)
a.sort()
index = 1
for i in range(n):
if a[i][0] == "1":
index = i
break
result = 1000000000000.0
for i in range(index):
for j in range(index, n):
result = min(result, int(a[i], 2) ^ int(a[j], 2))
print(result)
|
FUNC_DEF ASSIGN VAR VAR FOR VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n, data, r = int(input()), [int(x) for x in input().split(" ")], 0
def cal1(hbuf, lbuf):
if len(hbuf) == 1 and len(lbuf) == 1:
return list(hbuf)[0] ^ list(lbuf)[0]
mm, ms = max(max(hbuf), max(lbuf)), 1
while ms <= mm:
ms += ms
mh = ms >> 1
lz1 = set([(y - mh) for y in filter(lambda x: x & mh, hbuf)])
lz2 = set([x for x in filter(lambda x: not x & mh, hbuf)])
lv1 = set([(x - mh) for x in filter(lambda x: x & mh, lbuf)])
lv2 = set([x for x in filter(lambda x: not x & mh, lbuf)])
c1, c2 = None, None
if len(lz1) and len(lv1):
c1 = cal1(lz1, lv1)
if len(lz2) and len(lv2):
c2 = cal1(lz2, lv2)
if c1 == None:
c = c2
elif c2 == None:
c = c1
else:
c = min(c1, c2)
if c == None:
c = cal1(lz1 if len(lz1) else lz2, lv1 if len(lv1) else lv2) + mh
return c + r
while True:
mm, ms = max(data), 1
if mm == 0:
print(0)
break
while ms <= mm:
ms += ms
ms >>= 1
s1 = set(map(lambda x: x - ms, filter(lambda x: x >= ms, data)))
s2 = set(filter(lambda x: x < ms, data))
if not s2:
data = [(x - ms) for x in data]
continue
print(cal1(s1, s2) + ms)
break
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NONE NONE IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE ASSIGN VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN BIN_OP VAR VAR WHILE NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
class Node:
def __init__(self, bit: int):
if bit != 0 and bit != 1:
raise ValueError(
"An argument called bit... maybe you should give it a value of either 0 or 1!"
)
self.bit = bit
self.children = [None, None]
def addNumber(root: Node, v: int):
mask = 2**31
while mask > 0:
nextBit = int(not not v & mask)
if root.children[nextBit] is None:
root.children[nextBit] = Node(nextBit)
root = root.children[nextBit]
mask >>= 1
def solve(root: Node):
while root.children.count(None) == 1:
root = root.children[0] if root.children[0] is not None else root.children[1]
if root.children.count(None) == 2:
return 0
result = subsolve(*root.children)
return restoint(result)
def restoint(result):
intres = 0
for x in result:
intres <<= 1
intres |= x
return intres
subsolve_table = [
[[], [], [], []],
[[], [1, 1], [1, 0], [1, 1]],
[[], [0, 1], [0, 0], [0, 0]],
[[], [1, 1], [0, 0], None],
]
def subsolve(l: Node, r: Node):
lc = list(map(lambda x: int(x is not None), l.children))
lc = lc[0] * 2 + lc[1]
rc = list(map(lambda x: int(x is not None), r.children))
rc = rc[0] * 2 + rc[1]
entry = subsolve_table[lc][rc]
b = [l.bit ^ r.bit]
if entry is None:
return b + min(
subsolve(l.children[0], r.children[0]),
subsolve(l.children[1], r.children[1]),
key=restoint,
)
elif len(entry) == 0:
return b
else:
return b + subsolve(l.children[entry[0]], r.children[entry[1]])
input()
root = Node(0)
for x in input().strip().split():
x = int(x)
addNumber(root, x)
print(solve(root))
|
CLASS_DEF FUNC_DEF VAR IF VAR NUMBER VAR NUMBER FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR LIST NONE NONE FUNC_DEF VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR IF VAR VAR NONE ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER FUNC_DEF VAR WHILE FUNC_CALL VAR NONE NUMBER ASSIGN VAR VAR NUMBER NONE VAR NUMBER VAR NUMBER IF FUNC_CALL VAR NONE NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR LIST LIST LIST LIST LIST LIST LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER LIST NUMBER NUMBER LIST LIST LIST NUMBER NUMBER LIST NUMBER NUMBER NONE FUNC_DEF VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NONE VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NONE VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR LIST BIN_OP VAR VAR IF VAR NONE RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def permutation_gen(aa):
stack = [([], aa)]
while stack:
p, rest = stack.pop()
if not rest:
yield p
else:
for i, r in enumerate(rest):
stack.append((p + [r], rest[:i] + rest[i + 1 :]))
def score(aa):
rval = None
for a, b in zip(aa, aa[1:]):
x = a ^ b
if not rval or rval < x:
rval = x
return rval
def solve_bf(aa):
print("aa=%s" % aa, file=sys.stderr)
rval = None
for p in permutation_gen(aa):
s = score(p)
print("s=%d p=%s" % (s, p), file=sys.stderr)
if rval is None or rval > s:
rval = s
return rval
def solve(aa):
def rbin_gen(a, width):
while a:
yield a % 2
width -= 1
a //= 2
while width > 0:
yield 0
width -= 1
print("aa=%s" % aa, file=sys.stderr)
mrb = list(rbin_gen(max(aa), 0))
width = len(mrb)
bb = [tuple(rbin_gen(a, width))[::-1] for a in aa]
print("bb=%s" % bb, file=sys.stderr)
lii, position = None, 0
while position != width:
lii = [i for i, b in enumerate(bb) if b[position] == 1]
if len(lii) < len(bb):
break
position += 1
print("position=%d lii=%s" % (position, lii), file=sys.stderr)
if position == width:
return 0
slii = set(lii)
rii = [i for i in range(len(bb)) if i not in slii]
print("rii=%s" % rii, file=sys.stderr)
rval = None
for i in lii:
a = aa[i]
for j in rii:
b = aa[j]
r = a ^ b
if rval is None or rval > r:
rval = r
return rval
_ = int(input())
aa = list(map(int, input().split()))
print(solve(aa))
|
IMPORT FUNC_DEF ASSIGN VAR LIST LIST VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR EXPR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR LIST VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF FUNC_DEF WHILE VAR EXPR BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR NUMBER EXPR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR VAR NONE NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING VAR VAR ASSIGN VAR NONE FOR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = list(map(int, input().split()))
try:
c = 1 << max(a).bit_length() - 1
while min(a) >= c:
a = [(i - c) for i in a]
c = 1 << max(a).bit_length() - 1
print(min(i ^ j for i in a for j in a if i < c and j >= c))
except:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL FUNC_CALL VAR VAR NUMBER WHILE FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = sorted([int(x) for x in input().split()])
idx = 0
while idx == 0 and a[-1] > 0:
max_bit = a[-1].bit_length()
while idx < n and a[idx].bit_length() < max_bit:
idx += 1
if idx == 0:
for i in range(n):
a[i] -= 1 << max_bit - 1
res = 0
if a[-1] > 0:
res = 1 << 32
if a[-1] > 0:
for i in range(idx, n):
for j in range(idx):
res = min(res, a[i] ^ a[j])
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def anotherMinimaxProblem(a, n):
if all(e == 0 for e in a):
return 0
digit_keys = {}
for elem in a:
count = 0
while elem > 0:
one = elem % 2
if one == 1:
digit_keys[count] = digit_keys.get(count, 0) + 1
elem //= 2
count += 1
max_digit = 0
for key in digit_keys:
if digit_keys[key] != n:
max_digit = max(max_digit, key)
withZero = []
withOne = []
digit = 2**max_digit
for elem in a:
if elem & digit == 0:
withZero.append(elem)
else:
withOne.append(elem)
minXor = 10**9
for e1 in withZero:
for e2 in withOne:
minXor = min(minXor, e1 ^ e2)
return minXor
n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
result = anotherMinimaxProblem(a, n)
print(result)
|
IMPORT FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR VAR RETURN NUMBER ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = list(map(int, input().split()))
bitlen = max(x.bit_length() for x in a)
if bitlen == 0:
print(0)
else:
mask = 1 << bitlen - 1
while mask != 0:
msbzeroes = set()
msbones = set()
for x in a:
if x & mask == 0:
msbzeroes.add(x)
else:
msbones.add(x)
if len(msbzeroes) != 0 and len(msbones) != 0:
print(min(zero ^ one for zero in msbzeroes for one in msbones))
break
a = [(x & ~mask) for x in a]
mask >>= 1
else:
print(0)
|
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 FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = input()
arr = list(map(int, input().split()))
barr = ["{0:b}".format(i) for i in arr]
l = max([len(i) for i in barr])
barr = [("0" * (l - len(i)) + i) for i in barr]
while all([(i[0] == "1") for i in barr]):
barr = [i[1:] for i in barr]
barr = sorted(barr)
i = 0
while i < len(barr) and barr[i][0] == "0":
i += 1
larr = barr[:i]
rarr = barr[i:]
if i == len(barr):
print(0)
else:
m = min([min([(int(j, 2) ^ int(k, 2)) for j in larr]) for k in rarr])
print(m)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR VAR VAR VAR VAR WHILE FUNC_CALL VAR VAR NUMBER STRING VAR VAR ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR VAR NUMBER STRING VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def solve(ar):
answer = 0
byLen = [
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
]
highestNonZeroLen = 0
uniqueness = False
latest = 1
for ni in range(len(ar)):
n = ar[ni]
if ni == 0:
latest = n
elif n != latest:
uniqueness = True
representation = "{0:b}".format(n)
replen = len(representation)
byLen[replen].append(n)
if replen > highestNonZeroLen:
highestNonZeroLen = replen
if uniqueness == False:
return 0
numPopulatedLens = 0
for i in byLen:
if len(i) > 0:
numPopulatedLens += 1
if numPopulatedLens != 1:
best = 2 ** (highestNonZeroLen - 1)
else:
best = 2 ** (highestNonZeroLen - 2)
worst = 2**highestNonZeroLen - 1
bestSoFar = worst
for i in byLen[highestNonZeroLen]:
for n in ar:
if n ^ i == best:
return best
elif best < n ^ i < bestSoFar:
bestSoFar = n ^ i
return bestSoFar
n = int(input().strip())
ar = list(map(int, input().strip().split(" ")))
result = solve(ar)
print(result)
|
IMPORT FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL STRING VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR VAR FOR VAR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR RETURN VAR IF VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def get_closest_power_2(x):
if x == 0:
return 0
v = 1
while v <= x:
v <<= 1
return v >> 1
def get_mask(x, y):
assert x >= y
if y == 0:
return 0
p_x = get_closest_power_2(x)
p_y = get_closest_power_2(y)
assert p_x > 0 and p_y > 0
if p_x != p_y:
return 0
else:
mask = 0
cur_mask = p_y
while cur_mask & y > 0:
mask |= cur_mask
cur_mask >>= 1
return mask
def max_xor(xs):
flag = get_closest_power_2(max(xs))
ones = []
zeros = []
for x in xs:
if x & flag > 0:
ones.append(x)
else:
zeros.append(x)
if len(ones) == 0:
return 0
best = 10**10
for one in ones:
for zero in zeros:
v = one ^ zero
if v < best:
best = v
return best
n = int(input())
xs = list(map(int, input().split()))
xs = sorted(xs, reverse=True)
x, y = xs[0], xs[-1]
m = get_mask(x, y)
print(max_xor([(m ^ v) for v in xs]))
|
FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER RETURN BIN_OP VAR NUMBER FUNC_DEF VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN 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 NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = list(map(int, input().split()))
ind = 0
x = max(a)
while x:
ind += 1
x >>= 1
d = {}
for i in range(ind + 1):
d[i] = []
for el in a:
if el & 1 << i:
d[i].append(el)
while ind >= 0 and len(d[ind]) == n or len(d[ind]) == 0:
ind -= 1
if ind < 0:
break
res = 0
if ind >= 0:
res = 10000000000
good = set()
for el in d[ind]:
good.add(el)
for el in d[ind]:
for num in a:
if not num in good:
res = min(res, el ^ num)
print(res)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR NUMBER VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR WHILE VAR NUMBER FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
_ = int(input())
lst = list(map(int, input().split()))
def find_left_most_1(n):
cnt = 0
while n > 1:
n = n >> 1
cnt += 1
return cnt
def solution(lst):
max_n = max(lst)
if max_n == 0:
return 0
max_left = find_left_most_1(max_n)
all_max = set()
for i in lst:
if find_left_most_1(i) == max_left:
all_max.add(i)
if len(all_max) == len(lst):
new_lst = [(i - (1 << max_left)) for i in lst]
return solution(new_lst)
result = (1 << max_left + 1) - 1
for candidates in all_max:
for i in lst:
if i not in all_max:
temp = candidates ^ i
if temp < result:
result = temp
return result
print(solution(lst))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP NUMBER VAR VAR VAR RETURN FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR VAR FOR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = [int(x) for x in input().split()]
M, m = max(a), min(a)
maxbit = 2 ** (len(bin(M)) - 3)
while m >= maxbit:
a = [(x - maxbit) for x in a]
M, m = M - maxbit, m - maxbit
maxbit = 2 ** (len(bin(M)) - 3)
small, large = [], []
for x in a:
if x < maxbit:
small.append(x)
else:
large.append(x)
if not large:
large = [0]
print(min(s ^ l for s in small for l in large))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR ASSIGN VAR LIST NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def bin_len(number):
return len(bin(number)) - 2
def trim(numbers):
numbers = sorted(numbers)
min_bits, max_bits = bin_len(numbers[0]), bin_len(numbers[-1])
while min_bits == max_bits and max_bits > 1:
mask = 2 ** (min_bits - 1) - 1
numbers = [(n & mask) for n in numbers]
min_bits, max_bits = bin_len(numbers[0]), bin_len(numbers[-1])
return numbers
def find_perm_min(numbers):
numbers = trim(numbers)
if numbers[0] == numbers[-1]:
return 0
max_len = bin_len(numbers[-1])
first_bit_diff = 0
for ix, n in enumerate(numbers):
n = list(map(int, bin(n)[2:]))
if len(n) == max_len and n[0] == 1:
first_bit_diff = ix
break
perm_min = float("Inf")
for lesser in numbers[:first_bit_diff]:
for greater in numbers[first_bit_diff:]:
xor = greater ^ lesser
if xor < perm_min:
perm_min = xor
return perm_min
n, numbers = int(input()), map(int, input().split())
print(find_perm_min(numbers))
|
FUNC_DEF RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR VAR FOR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = [int(x) for x in input().split()]
bit = 1
for x in a:
while x > bit:
bit <<= 1
while bit:
a0 = []
a1 = []
for x in a:
if x & bit:
a1.append(x)
else:
a0.append(x)
if a0 and a1:
small = bit << 1
for x0 in a0:
for x1 in a1:
diff = x0 ^ x1
if diff < small:
small = diff
print(small)
break
bit >>= 1
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR VAR NUMBER WHILE VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = input()
arr = list(set(list(map(int, input().split()))))
arr2 = sorted(arr)
maxv = arr2[len(arr) - 1]
count = 0
while maxv > 0:
count = count + 1
maxv = maxv >> 1
if count == 0:
print(0)
else:
mask = 1 << count - 1
filteredtops = [(i ^ mask) for i in arr2 if i & mask == mask]
filteredbottoms = [i for i in arr2 if i & mask == 0]
while not filteredbottoms:
mask = mask >> 1
filteredtops = [(i ^ mask) for i in filteredtops if i & mask == mask]
filteredbottoms = [i for i in filteredtops if i & mask == 0]
addon = mask
for a in filteredtops:
for b in filteredbottoms:
if addon > a ^ b:
addon = a ^ b
if a ^ b == 0:
addon = 0
break
print(mask + addon)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
N = int(input())
arr = list(map(int, input().split()))
arrSmaller = [(0) for i in range(N)]
arrLarger = [(0) for i in range(N)]
numbersReduced = False
while not numbersReduced:
maxv = max(arr)
hsb = 1
while maxv >= hsb:
hsb *= 2
hsb //= 2
indLarger = 0
indSmaller = 0
for val in arr:
if val >= hsb:
arrLarger[indLarger] = val
indLarger += 1
else:
arrSmaller[indSmaller] = val
indSmaller += 1
if indSmaller == 0 and hsb > 0:
numbersReduced = False
for i in range(N):
arr[i] -= hsb
else:
numbersReduced = True
smallest = 2 * hsb
for i in range(indLarger):
for j in range(indSmaller):
if arrLarger[i] ^ arrSmaller[j] < smallest:
smallest = arrLarger[i] ^ arrSmaller[j]
print(smallest)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
input()
A = [int(i) for i in input().strip().split()]
k = 1 << max(A).bit_length()
while True:
P, Q = [], []
k >>= 1
for a in A:
if a & k:
P.append(a)
else:
Q.append(a)
if P and Q or k <= 1:
break
if P and Q:
best = P[0] ^ Q[0]
for p in P:
for q in Q:
val = p ^ q
if val < best:
best = val
print(best)
else:
print(0)
|
EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL FUNC_CALL VAR VAR WHILE NUMBER ASSIGN VAR VAR LIST LIST VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def bit_set(x, b):
return x & 1 << b != 0
def get_bit_options(arr, b):
foundZeros = False
foundOnes = False
for a in arr:
if bit_set(a, b):
foundOnes = True
else:
foundZeros = True
if foundOnes and foundZeros:
break
return foundZeros, foundOnes
def helper(left, right, b):
lo = get_bit_options(left, b)
ro = get_bit_options(right, b)
if b == 0:
if lo[0] and ro[0] or lo[1] and ro[1]:
return 0
else:
return 1
if lo == ro and not all(lo):
return helper(left, right, b - 1)
elif lo[0] ^ lo[1] and ro[0] ^ ro[1]:
return (1 << b) + helper(left, right, b - 1)
else:
left0 = [a for a in left if not bit_set(a, b)]
left1 = [a for a in left if bit_set(a, b)]
right0 = [a for a in right if not bit_set(a, b)]
right1 = [a for a in right if bit_set(a, b)]
result = 1 << b
if len(left0) > 0 and len(right0) > 0:
result = helper(left0, right0, b - 1)
if len(left1) > 0 and len(right1) > 0:
result = min(result, helper(left1, right1, b - 1))
return result
def solve(arr):
startBit = 31
while startBit >= 0:
if all(get_bit_options(arr, startBit)):
break
startBit -= 1
else:
return 0
left = [a for a in arr if not bit_set(a, startBit)]
right = [a for a in arr if bit_set(a, startBit)]
return (1 << startBit) + helper(left, right, startBit - 1)
n = int(input())
arr = list(map(int, input().strip().split()))
print(solve(arr))
|
FUNC_DEF RETURN BIN_OP VAR BIN_OP NUMBER VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER IF VAR VAR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER RETURN BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER WHILE VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
class MinMaxXor:
def __init__(self, arr, n):
self.n = n
self.a = list(sorted(arr))
self.mbl = self.a[n - 1].bit_length()
self.max_xor_sum = (1 << self.a[n - 1].bit_length()) - 1
self.splind = n
self.xor_sum = 0
self.reducer()
print(self.xor_sum)
def reducer(self):
while self.mbl > 0:
for i in range(self.n - 2, -1, -1):
if self.a[i].bit_length() != self.mbl:
self.splind = i + 1
self.xor_sum = self.get_min_xor_sum()
return
self.mbl -= 1
self.a = list(map(lambda x: x % (1 << self.mbl), self.a))
def get_min_xor_sum(self):
min_xor_sum = self.max_xor_sum
for i in range(self.splind):
for j in range(self.splind, self.n):
cur = self.a[i] ^ self.a[j]
if cur < min_xor_sum:
min_xor_sum = cur
return min_xor_sum
N = int(input().strip())
Arr = list(map(int, input().strip().split(" ")))
Cla = MinMaxXor(Arr, N)
|
CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_DEF WHILE VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR RETURN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
arr = list(map(int, input().strip().split()))
mx = -1
mxarr, mnarr = [], []
for x in arr:
l = x.bit_length() - 1
if l > mx:
mxarr = [x]
mx = l
elif l == mx:
mxarr.append(x)
fil = list(filter(lambda x: x not in mxarr, arr))
anarr = []
if len(fil) == 0:
print(mxarr[0] ^ mxarr[1])
else:
for x in mxarr:
for y in fil:
anarr.append(x ^ y)
print(min(anarr))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER IF VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = [int(x) for x in input().split(" ")]
more = True
while more:
if not (len(a) and a[0].bit_length() > 0):
break
bitMask = 1 << a[0].bit_length() - 1
for val in a:
if 0 == val & bitMask:
more = False
break
if more:
bitMask = ~bitMask
for i in range(len(a)):
a[i] = a[i] & bitMask
minInBottom = None
bitMask = 0
for val in a:
bits = val.bit_length()
if bits > 0 and 1 << bits - 1 > bitMask:
bitMask = 1 << bits - 1
if bitMask:
mi = None
for val in a:
if val & bitMask:
for val2 in a:
if 0 == val2 & bitMask:
if mi == None or val ^ val2 < mi:
mi = val ^ val2
print(mi)
else:
print(0)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER WHILE VAR IF FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR VAR IF NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR IF VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP NUMBER BIN_OP VAR NUMBER IF VAR ASSIGN VAR NONE FOR VAR VAR IF BIN_OP VAR VAR FOR VAR VAR IF NUMBER BIN_OP VAR VAR IF VAR NONE BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n = int(input())
a = list(map(int, input().split()))
max_num = max(a)
digits = len(bin(int(max_num))[2:])
a = [("0" * (digits - len(bin(int(i))[2:])) + bin(int(i))[2:]) for i in a]
while True:
for i in range(len(a)):
if a[i][0] == "0":
break
else:
a = [i[1:] for i in a]
continue
break
leading_ones = set()
leading_zeros = set()
for i in a:
if i[0] == "0":
leading_zeros.add(int(i, 2))
else:
leading_ones.add(int(i, 2))
result = float("inf")
for i in leading_ones:
for j in leading_zeros:
if i ^ j < result:
result = i ^ j
if not leading_ones:
print(0)
else:
print(int(result))
|
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP STRING BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR VAR WHILE NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER STRING ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR NUMBER STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
import sys
def anotherMinimaxProblem(a):
a.sort()
t = 0
while 2**t <= a[-1]:
t += 1
ander = ["1" for x in range(t)]
if ander == []:
return 0
ander = int("".join(ander), 2)
ander2 = ander
for i in a:
ander = ander & i
ander2 = ander2 ^ ander
tt = 0
while 2**tt < ander2:
tt += 1
tt = tt - 1
seta = []
setb = []
x = int(2**tt)
lap = int(2 ** (tt + 1))
for i in a:
if i % lap >= x:
seta.append(i)
else:
setb.append(i)
minimum = seta[0] ^ setb[0]
for i in seta:
for j in setb:
temp = i ^ j
if temp < minimum:
minimum = temp
return minimum
n = int(input().strip())
a = list(map(int, input().strip().split(" ")))
result = anotherMinimaxProblem(a)
print(result)
|
IMPORT FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING VAR FUNC_CALL VAR VAR IF VAR LIST RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL STRING VAR NUMBER ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER WHILE BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
def bit_length(k):
return k.bit_length()
def occurence(arr):
s = 0
for i in range(len(arr)):
if arr[i] == arr[0]:
s += 1
return s
def transf(ar, occ):
if occ == len(ar) and ar[0].bit_length() > 1:
a = ar[0].bit_length() - 1
for i in range(occ):
ar[i] = ar[i] % 2**a
bit_ar = list(map(bit_length, ar))
occ = occurence(bit_ar)
transf(ar, occ)
return occ
n = int(input().strip())
ar = list(map(int, input().strip().split(" ")))
ar.sort(reverse=True)
bit_ar = list(map(bit_length, ar))
occ = occurence(bit_ar)
occ = transf(ar, occ)
if occ != n:
ar1 = ar[:occ]
ar2 = ar[occ:]
arr = []
for i in range(len(ar1)):
for j in range(len(ar2)):
arr.append(ar1[i] ^ ar2[j])
arr.sort()
print(arr[0])
elif ar[0] == ar[-1]:
print(0)
else:
print(1)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER VAR NUMBER RETURN VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER
|
You are given $n$ non-negative integers, $a_0,a_1,\ldots,a_{n-1}$. We define the score for some permutation ($\boldsymbol{p}$) of length $n$ to be the maximum of $a_{p_i}\oplus a_{p_{i+1}}$ for $0\leq i<n-1$.
Find the permutation with the minimum possible score and print its score.
Note: $\oplus$ is the exclusive-OR (XOR) operator.
Input Format
The first line contains single integer, $n$, denoting the number of integers.
The second line contains $n$ space-separated integers, $a_0,a_1,\ldots,a_{n-1}$, describing the respective integers.
Constraints
$2\leq n\leq3000$
$0\leq a_i\leq10^9$
Output Format
Print a single integer denoting the minimum possible score.
Sample Input 0
4
1 2 3 4
Sample Output 0
5
Sample Input 1
3
1 2 3
Sample Output 1
2
Explanation
Sample Case 0:
The permutation with the minimum score is $(3,2,1,4)$:
$a_0\oplus a_1=3\oplus2=1$
$a_1\oplus a_2=2\oplus1=3$
$a_2\oplus a_3=1\oplus4=5$
Because the permutation's score is the maximum of these values, we print $5$ on a new line.
Sample Case 1:
The permutation with the minimum score is $(1,3,2)$:
$a_0\oplus a_1=1\oplus3=2$
$a_1\oplus a_2=3\oplus2=1$
Because the permutation's score is the maximum of these values, we print $2$ on a new line.
|
n, a = int(input()), list(map(int, input().split()))
up, down = [], []
while len(down) == 0:
maxBit = 1 << max([len(bin(i)) for i in a]) - 3
for i in a:
if i >= maxBit:
up.append(i)
else:
down.append(i)
if len(down) == 0:
for i in range(n):
a[i] ^= maxBit
minimum = 10000000000
for i in up:
for j in down:
minimum = min(minimum, i ^ j)
if len(up) == 0:
print(0)
else:
print(minimum)
|
ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR LIST LIST WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
arr = [int(_) for _ in input("").split()]
p = n // 2
if n % 2 == 0:
p = (n - 1) // 2
xor = arr[0]
for i in range(1, n):
xor ^= arr[i]
if n % 2 != 0 or xor == 0 and n % 2 == 0:
print("YES")
print(2 * p - 1)
a = 1
for i in range(p):
print(a, a + 1, a + 2)
a += 2
a -= 4
for i in range(p - 1):
print(a, a + 1, a + 2)
a -= 2
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 1:
print("YES")
print(n - 1)
for i in range(n // 2):
print(2 * i + 1, 2 * i + 2, n)
for i in range(n // 2):
print(2 * i + 1, 2 * i + 2, n)
else:
ct = [0] * 31
for x in a:
for bit in range(31):
ct[bit] ^= x >> bit & 1
if max(ct) == 1:
print("NO")
else:
print("YES")
print(n - 2)
for i in range(n // 2 - 1):
print(2 * i + 1, 2 * i + 2, n - 1)
for i in range(n // 2 - 1):
print(2 * i + 1, 2 * i + 2, n - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
from sys import stdin
input = stdin.readline
def solve():
n = int(input())
a = list(map(int, input().split()))
if n & 1 == 0:
s = 0
for i, v in enumerate(a):
s ^= v
if s != 0:
print("NO")
return
print("YES")
last = n if n & 1 == 1 else n - 1
print(last - 1)
res = []
for i in range(1, n - 1 if n & 1 == 1 else n - 2, 2):
res.append([i, i + 1, i + 2])
for i in range(1, n - 1 if n & 1 == 1 else n - 2, 2):
res.append([i, i + 1, last])
print("\n".join(" ".join(map(str, i)) for i in res))
solve()
|
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
c = 0
n = int(input())
ans = list(map(int, input().split()))
if n % 2 == 0:
xor = 0
for i in ans:
xor = xor ^ i
if xor != 0:
print("NO")
else:
print("YES")
n = n - 1
num = n // 2
print(num + num - 1)
oper = num + num - 1
i = 1
while i < n:
print(i, i + 1, i + 2)
i += 2
i = 1
while i <= n - 3:
print(i, i + 1, n)
i += 2
else:
print("YES")
num = n // 2
print(num + num - 1)
oper = num + num - 1
i = 1
while i < n:
print(i, i + 1, i + 2)
i += 2
i = 1
while i <= n - 3:
print(i, i + 1, n)
i += 2
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
t = 1
while t > 0:
t -= 1
n = int(input())
l = list(map(int, input().split()))
flag = 1
if n % 2 == 0:
total = 0
for i in range(n):
total ^= l[i]
if total != 0:
flag = 0
exit
n -= 1
if flag == 0:
print("NO")
else:
print("YES")
print(n - 1)
for i in range((n - 1) // 2):
print(1, 2 * i + 2, 2 * i + 3)
for i in range((n - 1) // 2):
print(1, 2 * i + 2, 2 * i + 3)
|
ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER EXPR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
s = input()
list1 = s.split()
t = 0
for i in range(n):
t = t ^ int(list1[i])
if n % 2 == 0 and t != 0:
print("NO")
elif n % 2 == 0:
print("YES")
n = n - 1
print(n - 2)
for i in range(1, n - 1, 2):
print(i, i + 1, i + 2)
i = n - 2
while i >= 3:
print(i - 2, i - 1, i)
i = i - 2
else:
print("YES")
print(n - 2)
for i in range(1, n - 1, 2):
print(i, i + 1, i + 2)
i = n - 2
while i >= 3:
print(i - 2, i - 1, i)
i = i - 2
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
l = [int(x) for x in input().split()]
xx = 0
for i in l:
xx = xx ^ i
if n % 2 == 0 and xx != 0:
print("NO")
else:
print("YES")
ans = []
for i in range(3, n + 1, 2):
ans.append([i - 2, i - 1, i])
for i in range(2, n, 2):
ans.append([i - 1, i, n])
print(len(ans))
for i in ans:
print(*i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
from sys import stdin
def c(i, j, k):
tmp = a[i] ^ a[j] ^ a[k]
a[i] = tmp
a[j] = tmp
a[k] = tmp
tt = 1
for loop in range(tt):
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
if n % 2 == 1:
ans = []
for i in range(0, n - 2, 2):
ans.append((i + 1, i + 2, i + 3))
c(i, i + 1, i + 2)
for i in range(n - 3, -1, -2):
ans.append((i + 1, i + 2, i + 3))
c(i, i + 1, i + 2)
print("YES")
print(len(ans))
for i in ans:
print(*i)
else:
last = a[-1]
a = a[:-1]
n -= 1
ans = []
for i in range(0, n - 2, 2):
ans.append((i + 1, i + 2, i + 3))
c(i, i + 1, i + 2)
for i in range(n - 3, -1, -2):
ans.append((i + 1, i + 2, i + 3))
c(i, i + 1, i + 2)
if a[0] == last:
print("YES")
print(len(ans))
for i in ans:
print(*i)
else:
print("NO")
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER 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 IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = list(map(int, input().split()))
res = "YES"
if n % 2 != 0:
res = "YES"
else:
xor = 0
n -= 1
for i in a:
xor ^= i
if xor == 0:
res = "YES"
else:
res = "NO"
if res == "YES":
print("YES")
print(n - 1)
i = 1
while i < n:
print(1, i + 1, i + 2)
i += 2
i = 1
while i < n:
print(1, i + 1, i + 2)
i += 2
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR STRING IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR NUMBER VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING IF VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
input = sys.stdin.readline
def main():
n = int(input())
alst = list(map(int, input().split()))
if n % 2 == 1:
print("YES")
ans = []
for i in range(3, n + 1, 2):
ans.append([i - 2, i - 1, i])
for i in range(3, n - 1, 2):
ans.append([i - 2, i - 1, n])
print(len(ans))
for row in ans:
print(*row)
else:
tmp = 0
for a in alst:
tmp ^= a
if tmp != 0:
print("NO")
return
print("YES")
ans = []
for i in range(3, n + 1, 2):
ans.append([i - 2, i - 1, i])
for i in range(3, n - 1, 2):
ans.append([i - 2, i - 1, n])
print(len(ans))
for row in ans:
print(*row)
for _ in range(1):
main()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = list(map(int, input().split()))
f = 0
even = False
if n % 2 == 0:
even = True
xor = a[0]
for i in a[1:]:
xor = xor ^ i
if xor != 0:
f = 1
if f == 1:
print("NO")
else:
print("YES")
if not even:
print(n // 2 + n // 2)
for i in range(0, n - 1, 2):
v = a[i] ^ a[i + 1] ^ a[n - 1]
a[i], a[i + 1], a[n - 1] = v, v, v
print(i + 1, i + 2, n)
for i in range(0, n - 1, 2):
v = a[i] ^ a[i + 1] ^ a[n - 1]
a[i], a[i + 1], a[n - 1] = v, v, v
print(i + 1, i + 2, n)
else:
print(n - 1)
for i in range(0, n - 2, 2):
v = a[i] ^ a[i + 1] ^ a[n - 1]
a[i], a[i + 1], a[n - 1] = v, v, v
print(i + 1, i + 2, n)
for i in range(0, n - 2, 2):
v = a[i] ^ a[i + 1] ^ a[n - 1]
a[i], a[i + 1], a[n - 1] = v, v, v
print(i + 1, i + 2, n)
print(n - 2, n - 1, n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
from sys import exit
n = int(input())
a = [int(i) for i in input().split()]
if n % 2 == 0:
kek = 0
for el in a:
kek ^= el
if kek != 0:
print("NO")
exit(0)
else:
n -= 1
print("YES")
print(n - 1)
for i in range((n - 1) // 2):
print(1, 2 * (i + 1), 2 * (i + 1) + 1)
for i in range((n - 1) // 2):
print(1, 2 * (i + 1), 2 * (i + 1) + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER BIN_OP VAR NUMBER NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = [int(x) for x in input().split()]
xor = 0
if len(a) % 2 == 0:
for i in a:
xor ^= i
if n % 2 == 0 and xor != 0:
print("NO")
else:
print("YES")
arr = [(i, i + 1, i + 2) for i in range(1, n - 1, 2)]
arr += arr[::-1][1:]
print(len(arr))
for i, j, k in arr:
print(i, j, k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.buffer.readline())
def MI():
return map(int, sys.stdin.buffer.readline().split())
def LI():
return list(map(int, sys.stdin.buffer.readline().split()))
def LLI(rows_number):
return [LI() for _ in range(rows_number)]
def BI():
return sys.stdin.buffer.readline().rstrip()
def SI():
return sys.stdin.buffer.readline().rstrip().decode()
n0 = II()
n = n0 if n0 & 1 else n0 - 1
aa = LI()
ans = []
for i in range(0, n - 2, 2):
aa[i] = aa[i + 1] = aa[i + 2] = aa[i] ^ aa[i + 1] ^ aa[i + 2]
ans.append((i + 1, i + 2, i + 3))
if n0 & 1 == 0 and aa[-1] != aa[-2]:
print("NO")
exit()
for i in range(0, n - 4, 2):
aa[i] = aa[i + 1] = aa[-1] = aa[i] ^ aa[i + 1] ^ aa[-1]
ans.append((i + 1, i + 2, n))
print("YES")
print(len(ans))
for i, j, k in ans:
print(i, j, k)
|
IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
ans = []
for i in range(0, len(arr) - 2, 2):
arr[i] = arr[i + 1] = arr[i + 2] = arr[i] ^ arr[i + 1] ^ arr[i + 2]
ans.append((i, i + 1, i + 2))
for i in range(0, len(arr) - 2, 2):
arr[i] = arr[i + 1] = arr[i] ^ arr[i + 1] ^ arr[len(arr) - 1]
ans.append((i, i + 1, len(arr) - 1))
possible = True
for i in range(len(arr) - 1, 0, -1):
if arr[i] != arr[i - 1]:
possible = False
break
if possible:
print("YES")
print(len(ans))
for thing in ans:
print(thing[0] + 1, thing[1] + 1, thing[2] + 1)
else:
print("NO")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
from sys import stdin, stdout
def powerful_ksenia(n, a_a):
xor = 0
for a in a_a:
xor ^= a
if n % 2 == 0 and xor != 0:
return ["NO"]
else:
r_a = ["YES", str((n - 1) // 2 * 2)]
for i in range((n - 1) // 2):
r_a.append(str(1) + " " + str(i * 2 + 2) + " " + str(i * 2 + 3))
for i in range((n - 1) // 2):
r_a.append(str(1) + " " + str(i * 2 + 2) + " " + str(i * 2 + 3))
return r_a
n = int(stdin.readline())
a_a = list(map(int, stdin.readline().split()))
r_a = powerful_ksenia(n, a_a)
for r in r_a:
stdout.write(r + "\n")
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN LIST STRING ASSIGN VAR LIST STRING FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR NUMBER STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER STRING FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER RETURN 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 VAR FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
def solve(n, arr):
xor_sum = arr[0]
for i in range(1, n):
xor_sum ^= arr[i]
if n % 2 == 0:
if xor_sum:
print("NO")
return
else:
n -= 1
if n == 3:
print(1)
print(1, 2, 3)
return
print("YES")
print(n - 2)
for i in range(1, n - 1, 2):
print(i, i + 1, i + 2)
for i in range(n - 4, 0, -2):
print(i, i + 1, i + 2)
n = int(input())
arr = list(map(int, input().split()))
solve(n, arr)
|
FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR EXPR FUNC_CALL VAR STRING RETURN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = list(map(int, input().split()))
def solveOdd(a, n):
a = [(a[i], i + 1) for i in range(n)]
a.sort(key=lambda x: x[0])
ans = []
for i in range(0, n - 2, 2):
ans.append((a[i][1], a[i + 1][1], a[i + 2][1]))
x = a[i][0] ^ a[i + 1][0] ^ a[i + 2][0]
a[i : i + 3] = (x, a[i][1]), (x, a[i + 1][1]), (x, a[i + 2][1])
for i in range(n - 3, -1, -2):
ans.append((a[i][1], a[i + 1][1], a[n - 1][1]))
x = a[i][0] ^ a[i + 1][0] ^ a[n - 1][0]
a[i : i + 3] = (x, a[i][1]), (x, a[i + 1][1]), (x, a[n - 1][1])
print(len(ans))
for x in ans:
print(x[0], x[1], x[2])
if n % 2:
print("YES")
solveOdd(a, n)
else:
x = 0
for i in range(n):
x ^= a[i]
if x != 0:
print("NO")
else:
print("YES")
solveOdd(a, n - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
for _ in range(1):
n = int(input())
arr = list(map(int, input().split()))
out = []
if n % 2:
i = 2
while i < n:
out.append([i - 1, i, i + 1])
k = arr[i - 2] ^ arr[i - 1] ^ arr[i]
arr[i - 2], arr[i - 1], arr[i] = k, k, k
i += 2
i = 1
while i < n - 3:
out.append([i, i + 1, n])
arr[i - 1] = arr[-1]
arr[i] = arr[-1]
i += 2
print("YES")
print(len(out))
for i in out:
print(*i)
else:
g = 0
for i in arr:
g ^= i
if g:
print("NO")
else:
arr = arr[:-1]
n -= 1
i = 2
while i < n:
out.append([i - 1, i, i + 1])
k = arr[i - 2] ^ arr[i - 1] ^ arr[i]
arr[i - 2], arr[i - 1], arr[i] = k, k, k
i += 2
i = 1
while i < n - 3:
out.append([i, i + 1, n])
arr[i - 1] = arr[-1]
arr[i] = arr[-1]
i += 2
print("YES")
print(len(out))
for i in out:
print(*i)
|
FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST IF BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
input = sys.stdin.readline
def prog():
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 0:
tot = 0
for i in a:
tot ^= i
if tot != 0:
print("NO")
return
print("YES")
print(n - 1 - (n % 2 == 0))
for j in range(2):
for i in range(2, n - (n % 2 == 0) + 1, 2):
print(1, i, i + 1)
prog()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
XOR = 0
for a in A:
XOR ^= a
if n % 2 == 0 and XOR != 0:
print("NO")
sys.exit()
print("YES")
ANS = []
for i in range(2, n, 2):
ANS.append((1, i, i + 1))
for i in range(2, n, 2):
ANS.append((1, i, i + 1))
print(len(ANS))
for i, j, k in ANS:
sys.stdout.write(str(i) + " " + str(j) + " " + str(k) + " " + "\n")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING FUNC_CALL VAR VAR STRING STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
def resu(n, L):
s = 0
if n == 3:
return [(1, 2, 3)]
for i in range(n):
x = L[i]
s = x ^ s
if n % 2 == 0 and s != 0:
return -1
if n % 2 == 1:
res = []
for _ in range(2):
for i in range((n - 1) // 2):
j = 2 * i + 1
res.append((1, j + 1, j + 2))
return res
L.pop(-1)
return resu(n - 1, L)
n = int(input())
L = [int(x) for x in input().split()]
K = resu(n, L)
if K == -1:
print("NO")
else:
print("YES")
print(len(K))
for x in K:
a, b, c = x
print(a, end=" ")
print(b, end=" ")
print(c)
|
FUNC_DEF ASSIGN VAR NUMBER IF VAR NUMBER RETURN LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR EXPR FUNC_CALL VAR NUMBER RETURN FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = list(map(int, input().split()))
if n % 2 != 0:
print("YES")
print(n - 2)
for i in range(n):
print(i * 2 + 1, i * 2 + 2, i * 2 + 3)
if i * 2 + 3 == n:
break
for i in range(2, n):
if n - i * 2 + 2 < 3:
break
print(n - i * 2, n - i * 2 + 1, n - i * 2 + 2)
else:
xor = 0
for num in a:
xor = xor ^ num
if xor != 0:
print("NO")
else:
n -= 1
print("YES")
print(n - 2)
for i in range(n):
print(i * 2 + 1, i * 2 + 2, i * 2 + 3)
if i * 2 + 3 == n:
break
for i in range(2, n):
if n - i * 2 + 2 < 3:
break
print(n - i * 2, n - i * 2 + 1, n - i * 2 + 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP BIN_OP VAR NUMBER NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
from sys import *
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
def solve(a, n):
if n == 1:
return []
if n == 3:
return [[1, 2, 3]]
if n % 2 == 1:
ops = []
for i in range(0, n - 2, 2):
ops.append([i + 1, i + 2, i + 3])
for i in reversed(range(0, n - 3, 2)):
ops.append([i + 1, i + 2, i + 3])
return ops
else:
x = 0
for y in a:
x ^= y
if x != 0:
print("NO")
exit(0)
ops = [[1, 2, 3]]
a = a[3:]
add = solve(a, n - 3)
for i in range(len(add)):
ops.append([(add[i][j] + 3) for j in range(3)])
return ops
ops = solve(a, n)
print("YES")
print(len(ops))
for i in range(len(ops)):
print(ops[i][0], ops[i][1], ops[i][2])
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN LIST IF VAR NUMBER RETURN LIST LIST NUMBER NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = list(map(int, input().split()))
if n & 1:
print("YES")
print(n - 1)
for i in range(1, n, 2):
print(i, i + 1, i + 2)
for i in range(1, n, 2):
print(i, i + 1, n)
else:
s = 0
for i in a:
s ^= i
if s > 0:
print("NO")
else:
print("YES")
print(n - 2)
for i in range(1, n - 1, 2):
print(i, i + 1, i + 2)
print(i, i + 1, n)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
input = sys.stdin.readline
n = int(input())
l = input().split()
li = [int(i) for i in l]
xori = 0
for i in range(n):
xori ^= li[i]
if xori == 0 or n % 2:
print("YES")
ans = []
if n % 2 == 0:
n -= 1
for i in range(n // 2):
ans.append((2 * i + 1, 2 * i + 2, n))
for i in range(n // 2):
ans.append((2 * i + 1, 2 * i + 2, n))
print(len(ans))
for i in ans:
print(i[0], i[1], i[2])
else:
print("NO")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST IF BIN_OP VAR NUMBER NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
input = lambda: sys.stdin.readline().strip()
inp = lambda: list(map(int, sys.stdin.readline().strip().split()))
n = int(input())
a = list(map(int, input().split()))
def solve(a, n):
ans = []
i = 1
for j in range(n // 2):
ans.append([i, i + 1, i + 2])
i += 2
this = ans[-1][-1]
for j in range(n // 2):
ans.append([this, ans[j][1], ans[j][0]])
print("YES")
print(len(ans))
for i, j, k in ans:
print(i, j, k)
if n % 2 == 1:
solve(a, n)
else:
lol = 0
for i in a:
lol ^= i
if lol != 0:
print("NO")
else:
solve(a[: n - 1], n - 1)
|
IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
def solve():
n = int(input())
a = list(map(int, input().split()))
if n % 2 == 1:
number_of_operations, moves, _ = change_bits(a, n)
print_correct(moves, number_of_operations)
else:
number_of_operations, moves, a[:-1] = change_bits(a[:-1], n - 1)
if a[0] == a[-1]:
print_correct(moves, number_of_operations)
else:
print("NO")
def print_correct(moves, number_of_operations):
print("YES")
print(number_of_operations)
for move in moves:
print(move)
def change_bits(a, n):
number_of_operations = 0
moves = []
for i in range(2, n, 2):
number_of_operations += 1
bitwise = a[i - 2] ^ a[i - 1] ^ a[i]
a[i - 2] = bitwise
a[i - 1] = bitwise
a[i] = bitwise
moves.append(f"{i - 1} {i} {i + 1}")
for i in range(1, n - 1, 2):
number_of_operations += 1
bitwise = a[i - 1] ^ a[i] ^ a[n - 1]
a[i - 1] = bitwise
a[i] = bitwise
moves.append(f"{i} {i + 1} {n}")
return number_of_operations, moves, a
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING FUNC_DEF EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER STRING VAR STRING BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING BIN_OP VAR NUMBER STRING VAR RETURN VAR VAR VAR EXPR FUNC_CALL VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
n = int(input())
a = list(map(int, input().split()))
count = [0] * 40
for i in range(n):
for j in range(40):
if a[i] & 1 << j:
count[j] = (count[j] + 1) % 2
if n % 2 == 0 and sum(count) != 0:
print("NO")
sys.exit()
print("YES")
ans = []
ans.append("1 2 3")
if n == 3:
print(1)
print(1, 2, 3)
sys.exit()
if n % 2 == 1:
pointer = 3
while pointer + 4 <= n:
t = [str(pointer), str(pointer + 1), str(pointer + 2)]
ans.append(" ".join(t))
pointer += 2
t = [str(pointer), str(pointer + 1), str(pointer + 2)]
ans.append(" ".join(t))
pointer += 2
for i in range(1, pointer, 2):
t = [str(i), str(i + 1), str(pointer)]
ans.append(" ".join(t))
else:
pointer = 3
while pointer + 2 <= n:
t = [str(pointer), str(pointer + 1), str(pointer + 2)]
ans.append(" ".join(t))
t = [str(pointer - 1), str(pointer), str(pointer + 1)]
ans.append(" ".join(t))
pointer += 2
t = [str(pointer - 1), str(pointer), str(pointer + 1)]
ans.append(" ".join(t))
print(len(ans))
for i in ans:
print(i)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
arr = list(map(int, input().split()))
if n % 2 == 1:
print("YES")
print(n - 2)
print(*[1, 2, 3])
for x in range(2, n - 2, 2):
print(*[x + 1, x + 2, x + 3])
for x in range(0, n - 3, 2):
print(*[x + 1, x + 2, n])
else:
xor = 0
for i in range(n):
xor = xor ^ arr[i]
if xor == 0:
print("YES")
print(n - 3)
print(*[1, 2, 3])
for x in range(2, n - 3, 2):
print(*[x + 1, x + 2, x + 3])
for x in range(0, n - 4, 2):
print(*[x + 1, x + 2, n - 1])
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
l = input().split()
li = [int(i) for i in l]
xori = 0
for i in range(n):
xori ^= li[i]
if n % 2 == 0 and xori:
print("NO")
quit()
if n % 2 == 0:
n = n - 1
print("YES")
l = []
for i in range((n - 1) // 2):
l.append((2 * i + 1, 2 * i + 2, 2 * i + 3))
for i in range((n - 3) // 2):
l.append((2 * i + 1, 2 * i + 2, n))
print(len(l))
for i in l:
print(i[0], i[1], i[2])
quit()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
l = list(map(int, input().split()))
if len(set(l)) == 1:
print("YES")
print(0)
exit()
if n % 2 == 0:
ans = []
for i in range(1, n, 2):
if i + 1 < n and i + 2 < n:
ans.append([i + 1, i + 2, i + 3])
z = l[i] ^ l[i + 1] ^ l[i + 2]
l[i], l[i + 1], l[i + 2] = z, z, z
i = n - 3
while i >= 1:
if i - 1 >= 0 and i - 2 >= 0:
ans.append([i + 1, i, i - 1])
z = l[i] ^ l[i - 1] ^ l[i - 2]
l[i], l[i - 1], l[i - 2] = z, z, z
i -= 2
if len(set(l)) == 1:
print("YES")
print(len(ans))
for i in ans:
print(*i)
else:
print("NO")
else:
print("YES")
ans = []
for i in range(0, n, 2):
if i + 1 < n and i + 2 < n:
ans.append([i + 1, i + 2, i + 3])
i = n - 3
while i >= 0:
if i - 1 >= 0 and i - 2 >= 0:
ans.append([i + 1, i, i - 1])
i -= 2
print(len(ans))
for i in ans:
print(*i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR NUMBER IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
a = [int(x) for x in input().split()]
xor_sum = 0
for x in a:
xor_sum = xor_sum ^ x
if n % 2 == 0 and xor_sum != 0:
print("NO")
else:
print("YES")
l = [(x, x + 1, x + 2) for x in range(1, n - 1, 2)]
l += list(reversed(l))[1:]
print(len(l))
for x in l:
print(" ".join([str(y) for y in x]))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
mod = 10**9 + 7
def solve():
n = int(input())
a = list(map(int, input().split()))
s = 0
for x in a:
s = s ^ x
if s != 0 and n % 2 == 0:
print("NO")
return
ans = []
for i in range(3, n + 1, 2):
ans.append([i - 2, i - 1, i])
for i in range(2, n, 2):
ans.append([i - 1, i, n])
print("YES")
print(len(ans))
for i in range(len(ans)):
print(*ans[i])
t = 1
while t > 0:
solve()
t -= 1
|
ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
import sys
input = sys.stdin.readline
def solve(n):
print("YES")
ans = []
for i in range(0, n - 1, 2):
ans.append([i + 1, i + 2, i + 3])
for i in range(n - 2, -1, -2):
ans.append([n, i + 1, i])
print(len(ans))
for i in ans:
print(*i)
n = int(input())
a = list(map(int, input().split()))
if n % 2:
solve(n)
else:
x = a[0]
for i in range(1, n):
x = x ^ a[i]
if x != 0:
print("NO")
else:
solve(n - 1)
|
IMPORT ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR LIST VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR EXPR 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 IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
from sys import stdin, stdout
input = stdin.readline
t = 1
for _ in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
if n % 2:
print("YES")
print(n - 1)
for i in range(0, n - 2, 2):
print(i + 1, i + 2, n)
for i in range(0, n - 2, 2):
print(i + 1, i + 2, n)
else:
x = 0
for i in arr:
x ^= i
if x:
print("NO")
continue
print("YES")
print(n - 2)
for i in range(0, n - 3, 2):
print(i + 1, i + 2, n)
for i in range(0, n - 3, 2):
print(i + 1, i + 2, n)
|
ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
arr = [int(x) for x in input().split()]
xor = 0
answer = []
for elem in arr:
xor ^= elem
if n % 2 or not xor:
for i in range(0, n - 1 >> 1):
x = 2 * i
y = arr[x] ^ arr[x + 1] ^ arr[x + 2]
arr[x] = y
arr[x + 1] = y
arr[x + 2] = y
answer.append((x + 1, x + 2, x + 3))
for i in range(0, n - 1 >> 1):
x = 2 * i
y = arr[x] ^ arr[x + 1] ^ arr[n - 1]
arr[x] = y
arr[x + 1] = y
arr[n - 1] = y
answer.append((x + 1, x + 2, n))
print("YES")
print(len(answer))
for x, y, z in answer:
print(x, y, z)
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
n = int(input())
arr = [int(i) for i in input().split()]
if n % 2 == 1:
print("YES")
print(n - 2)
for i in range(n // 2):
print(str(2 * i + 1), str(2 * i + 2), str(2 * i + 3))
for i in range(n // 2 - 1):
print(str(2 * i + 1), str(2 * i + 2), str(n - 1))
else:
xor = arr[0]
for i in range(1, n):
xor = xor ^ arr[i]
if xor == 0:
print("YES")
print(n - 2)
for i in range(n // 2 - 1):
print(str(2 * i + 1), str(2 * i + 2), str(2 * i + 3))
for i in range(n // 2 - 1):
print(str(2 * i + 1), str(2 * i + 2), str(n - 1))
else:
print("NO")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING
|
Ksenia has an array $a$ consisting of $n$ positive integers $a_1, a_2, \ldots, a_n$.
In one operation she can do the following: choose three distinct indices $i$, $j$, $k$, and then change all of $a_i, a_j, a_k$ to $a_i \oplus a_j \oplus a_k$ simultaneously, where $\oplus$ denotes the bitwise XOR operation.
She wants to make all $a_i$ equal in at most $n$ operations, or to determine that it is impossible to do so. She wouldn't ask for your help, but please, help her!
-----Input-----
The first line contains one integer $n$ ($3 \leq n \leq 10^5$)Β β the length of $a$.
The second line contains $n$ integers, $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$)Β β elements of $a$.
-----Output-----
Print YES or NO in the first line depending on whether it is possible to make all elements equal in at most $n$ operations.
If it is possible, print an integer $m$ ($0 \leq m \leq n$), which denotes the number of operations you do.
In each of the next $m$ lines, print three distinct integers $i, j, k$, representing one operation.
If there are many such operation sequences possible, print any. Note that you do not have to minimize the number of operations.
-----Examples-----
Input
5
4 2 1 7 2
Output
YES
1
1 3 4
Input
4
10 4 49 22
Output
NO
-----Note-----
In the first example, the array becomes $[4 \oplus 1 \oplus 7, 2, 4 \oplus 1 \oplus 7, 4 \oplus 1 \oplus 7, 2] = [2, 2, 2, 2, 2]$.
|
from sys import stdin, stdout
t = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
if t % 2 != 0:
print("YES")
print(t - 2)
for i in range(1, t - 1, 2):
print("{} {} {}".format(i, i + 1, i + 2))
for i in range(1, t - 3, 2):
print("{} {} {}".format(i, i + 1, t))
else:
xor = 0
for i in arr:
xor = xor ^ i
if xor != 0:
print("NO")
else:
t = t - 1
print("YES")
print(t - 2)
for i in range(1, t - 1, 2):
print("{} {} {}".format(i, i + 1, i + 2))
for i in range(1, t - 3, 2):
print("{} {} {}".format(i, i + 1, t))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER VAR
|
Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well.
Construct an array of length N containing only positive integers in the range [1, 1000] such that there doesnβt exist a subarray that has all elements occurring in even frequency and the maximum element in the array is minimized. In case there are multiple solutions, you can output any.
------ Input Format ------
- First line will contain T, number of testcases. Then the testcases follow.
- Each testcase contains of a single line of input, one integer N.
------ Output Format ------
For each test case, output in a single line N space-separated integers representing the required array. If there are multiple solutions, you may output any.
------ Constraints ------
$1 β€ T β€ 500$
$1 β€ N β€ 1000$
----- Sample Input 1 ------
3
1
2
7
----- Sample Output 1 ------
1
2 1
1 2 3 2 1 2 3
----- explanation 1 ------
Test case $1$: $[1]$ is the obvious answer.
Test case $2$: Since we need two elements and they can't be the same (otherwise the frequency of that element of the whole array is even), $[2, 1]$ is the optimal answer. $[1, 2]$ is another optimal one.
Test case $3$: It can be proven that no construction exists with the maximum element of $2$.
|
for tc in range(int(input())):
n = int(input())
dp = [[1]]
st = 2
for x in range(2, n + 1):
if x % 2 == 0:
dp.append(dp[-1] + [st])
st += 1
else:
dp.append(dp[-1] + dp[-2])
if len(dp[-1]) >= n:
break
for x in dp[-1][0:n]:
print(x, end=" ")
print()
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER LIST VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR FOR VAR VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.