description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$.
For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s.
Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation.
-----Input-----
The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$).
The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$).
The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$).
-----Output-----
Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$.
-----Examples-----
Input
4 2
2 6 4 0
2 4
Output
2
Input
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
Output
0
Input
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
Output
147
-----Note-----
For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get. | MIN = 2**9 * 2
[n, m] = list(map(int, input().split()))
arr = []
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = []
a.sort(reverse=True)
b.sort(reverse=True)
summ = 0
incarr = []
for i in a:
inc = i & b[0]
for j in b:
x = i & j
if summ | x < summ | inc:
inc = x
incarr.append(inc)
summ = summ | inc
mx = max(incarr)
sol = mx
for i in a:
mini = i & b[0]
for j in b:
x = i & j
if sol | x < sol | mini:
mini = x
sol = sol | mini
print(sol) | ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN LIST VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF BIN_OP VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$.
For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s.
Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation.
-----Input-----
The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$).
The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$).
The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$).
-----Output-----
Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$.
-----Examples-----
Input
4 2
2 6 4 0
2 4
Output
2
Input
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
Output
0
Input
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
Output
147
-----Note-----
For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get. | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
M = [[(a[i] & b[j]) for j in range(m)] for i in range(n)]
res = 0
M = sorted(M, key=lambda x: min(x), reverse=True)
for x in M:
res = min([(e | res) for e in x])
print(res) | ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$.
For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s.
Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation.
-----Input-----
The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$).
The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$).
The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$).
-----Output-----
Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$.
-----Examples-----
Input
4 2
2 6 4 0
2 4
Output
2
Input
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
Output
0
Input
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
Output
147
-----Note-----
For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get. | import sys
input = sys.stdin.buffer.readline
I = lambda: list(map(int, input().split()))
n, m = I()
a = I()
b = I()
p = [(a[0] & b[j]) for j in range(m)]
for kk in range(513):
an = kk
ct = 0
for i in range(n):
po = 0
for j in range(m):
if a[i] & b[j] | kk == kk:
po = 1
break
if po:
ct += 1
else:
break
if ct == n:
print(kk)
sys.exit() | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$.
For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s.
Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation.
-----Input-----
The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$).
The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$).
The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$).
-----Output-----
Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$.
-----Examples-----
Input
4 2
2 6 4 0
2 4
Output
2
Input
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
Output
0
Input
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
Output
147
-----Note-----
For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get. | import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
n, m = nm()
a = nl()
b = nl()
a.insert(0, 0)
b.insert(0, 0)
def check(x):
for i in range(1, n + 1):
f = 0
for j in range(1, m + 1):
temp = a[i] & b[j]
if temp | x == x:
f = 1
break
if f == 0:
return 0
return 1
st = 0
for i in range(1, n + 1):
st |= a[i]
for ans in range(st + 1):
if check(ans):
print(ans)
break | IMPORT ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER NUMBER FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$.
For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s.
Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation.
-----Input-----
The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$).
The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$).
The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$).
-----Output-----
Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$.
-----Examples-----
Input
4 2
2 6 4 0
2 4
Output
2
Input
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
Output
0
Input
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
Output
147
-----Note-----
For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get. | def put():
return map(int, input().split())
n, m = put()
a = list(put())
b = list(put())
ans = 0
for i in range(int(2000000000.0)):
this = True
for j in range(n):
exist = False
for k in range(m):
if a[j] & b[k] & i == a[j] & b[k]:
exist = True
break
if not exist:
this = False
break
if this:
ans = i
break
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Boboniu likes bit operations. He wants to play a game with you.
Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$.
For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $c_i=a_i\& b_j$, where $\&$ denotes the bitwise AND operation. Note that you can pick the same $j$ for different $i$'s.
Find the minimum possible $c_1 | c_2 | \ldots | c_n$, where $|$ denotes the bitwise OR operation.
-----Input-----
The first line contains two integers $n$ and $m$ ($1\le n,m\le 200$).
The next line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($0\le a_i < 2^9$).
The next line contains $m$ integers $b_1,b_2,\ldots,b_m$ ($0\le b_i < 2^9$).
-----Output-----
Print one integer: the minimum possible $c_1 | c_2 | \ldots | c_n$.
-----Examples-----
Input
4 2
2 6 4 0
2 4
Output
2
Input
7 6
1 9 1 9 8 1 0
1 1 4 5 1 4
Output
0
Input
8 5
179 261 432 162 82 43 10 38
379 357 202 184 197
Output
147
-----Note-----
For the first example, we have $c_1=a_1\& b_2=0$, $c_2=a_2\& b_1=2$, $c_3=a_3\& b_1=0$, $c_4 = a_4\& b_1=0$.Thus $c_1 | c_2 | c_3 |c_4 =2$, and this is the minimal answer we can get. | import sys
input = sys.stdin.readline
for _ in range(1):
n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
for k in range(0, 2**9):
ct = 0
for i in range(n):
fl = 0
for j in range(m):
if a[i] & b[j] | k == k:
ct += 1
fl = 1
break
if fl == 0:
break
if ct == n:
print(k)
break | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for s in [*open(0)][2::2]:
a = (*map(int, s.split()),)
x = c = y = 0
for n in a:
x ^= n
for n in a:
y ^= n
if y == x:
c += 1
y = 0
print("NYOE S"[x < 1 or c > 1 :: 2]) | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR VAR FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER VAR NUMBER NUMBER |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | from itertools import accumulate
tests = int(input())
for t in range(tests):
n = int(input())
arr = map(int, input().split(" "))
pref = list(accumulate(arr, lambda a, b: a ^ b))
if pref[-1] == 0:
print("YES")
elif pref[-1] in pref[: n - 1] and 0 in pref[pref[: n - 1].index(pref[-1]) :]:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for q in range(t):
n = int(input())
arr = list(map(int, input().split()))
xor = 0
for i in range(n):
xor ^= arr[i]
if xor == 0:
print("YES")
else:
cnt = 0
xr = 0
for i in range(n):
xr ^= arr[i]
if xor == xr:
cnt += 1
xr = 0
if cnt >= 2:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def AGAGA_XOOORRR(size, ar):
xor = 0
for i in range(size):
xor ^= ar[i]
if xor == 0:
print("YES")
else:
count, xr = 0, 0
for i in range(size):
xr ^= ar[i]
if xor == xr:
count += 1
xr = 0
print("YES") if count >= 2 else print("NO")
T = int(input())
for _ in range(T):
n = int(input())
array = list(map(int, input().split()))
AGAGA_XOOORRR(n, array) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR VAR NUMBER FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve(l):
xor = 0
for i in l:
xor ^= i
if xor == 0:
return True
else:
n = len(l)
yor = 0
c = 0
for i in range(n):
yor ^= l[i]
if yor == xor:
yor = 0
c += 1
if yor == 0 and c > 1:
return True
else:
return False
for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
print("YES" if solve(l) else "NO") | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def xorOfArray(arr, n):
xor_arr = 0
for i in range(n):
xor_arr = xor_arr ^ arr[i]
return xor_arr
ram = int(input())
for cidk in range(ram):
a = int(input())
l = list(map(int, input().split()))
w = 0
x = xorOfArray(l, a)
if x == 0:
print("YES")
w = -1
if w == 0:
x = xorOfArray(l, a)
y = 0
z = x
q = 0
r = 0
for i in range(1, a):
y = y ^ l[i - 1]
z = z ^ l[i - 1]
if y == 0 and z == x:
q = 1
s = i
if y == x and z == 0:
r = 1
t = i
if q == 1 and r == 1 and s > t:
print("YES")
w = -2
break
if w == 0:
print("NO") | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for i in range(t):
n = int(input())
nums = list(map(int, input().split()))
ans = 0
flag = False
for i, j in enumerate(nums):
ans ^= j
if i != n - 1 and ans == 0:
flag = True
if ans:
temp = 0
cnt = 0
for i in nums:
temp ^= i
if temp == ans:
temp = 0
cnt += 1
print("YES" if cnt > 1 else "NO")
elif flag:
print("YES")
else:
left, right = [], []
ans = 0
for i in nums:
ans ^= i
left.append(ans)
for i in reversed(nums):
ans ^= i
right.append(ans)
right = list(reversed(right))
for i in range(n - 1):
if left[i] == right[i + 1]:
print("YES")
break
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR LIST LIST ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve(n, a):
base = a[0]
for i in range(1, n):
base ^= a[i]
if base == 0:
return "YES"
c = 0
xor = 0
for x in a:
xor ^= x
if xor == base:
c += 1
xor = 0
return "YES" if c >= 2 else "NO"
tt = int(input())
while tt > 0:
tt -= 1
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a)) | FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER RETURN VAR NUMBER STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for i in range(t):
x = int(input())
a = list(map(int, input().split()))
an = 0
for i in a:
an = an ^ i
flag = 0
if an == 0:
flag = 1
c = 0
f = 0
for i in a:
f = f ^ i
if f == an:
c += 1
f = 0
if c > 2:
flag = 1
if flag:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | DEBUG = False
if DEBUG:
input = open("input.txt", "r").readline
t = int(input())
for ignore in range(0, t):
n = int(input())
a = [*map(int, input().split())]
prec = ans = count = 0
for i in a:
prec ^= i
for i in a:
ans ^= i
if ans == prec:
count += 1
ans = 0
if count > 1 or prec < 1:
print("YES")
else:
print("NO") | ASSIGN VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR VAR FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def ass(l, n, axor):
ans = 0
for i in range(n - 1):
ans ^= l[i]
xor = ans ^ axor
if ans == xor:
return True
elif xor == 0:
flag = 0
for j in range(i + 1, n):
if ans == xor:
return True
xor ^= l[j]
return False
t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
assxor = 0
for i in l:
assxor ^= i
print("YES" if ass(l, n, assxor) else "NO") | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR RETURN NUMBER VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
from itertools import combinations
for _ in range(int(input())):
n = int(input())
arr = list(map(int, sys.stdin.readline().split()))
flag = 0
acc = [arr[0]]
for i in arr[1:]:
acc.append(acc[-1] ^ i)
for b in range(n - 1):
if acc[b] == acc[b] ^ acc[-1]:
flag = 1
break
for b1, b2 in combinations([i for i in range(n)], 2):
if acc[b1] == acc[b1] ^ acc[b2] == acc[b2] ^ acc[-1]:
flag = 1
break
print("YES" if flag else "NO") | IMPORT FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
x = 0
for v in a:
x ^= v
if x == 0:
print("YES")
else:
y = a[0]
si = 0
while y != x:
si += 1
if si >= n:
break
y ^= a[si]
z = a[n - 1]
ei = n - 1
while z != x:
ei -= 1
if ei <= si:
break
z ^= a[ei]
if si < n - 1 and ei > 0 and ei - si - 1 > 0:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
x = 0
for i in l:
x ^= i
if not x:
print("YES")
else:
t = x
x = 0
c = 0
for i in l:
x ^= i
if x == t:
x = 0
c += 1
print("YES" if c >= 3 else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def check2(a):
xo = 0
for i in a:
xo ^= i
if xo == 0:
return 1
else:
return 0
def check3(a):
c = 0
comp = 0
for i in a:
comp ^= i
for i in range(1, len(a)):
c ^= a[i - 1]
now = comp ^ c
d = 0
for j in range(i, len(a)):
d ^= a[j]
if d == c and c == now ^ d:
return 1
return 0
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
x = check2(a)
y = check3(a)
if x or y:
print("YES")
else:
print("NO") | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR BIN_OP VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
ls = [int(x) for x in input().split()]
xorsum = 0
ans = 0
for i in ls:
xorsum ^= i
if xorsum == 0:
ans = 1
if ans == 0:
xorsum2 = 0
cnt = 0
for i in ls:
xorsum2 ^= i
if xorsum2 == xorsum:
xorsum2 = 0
cnt += 1
if ans == 0:
if xorsum2 == 0 and cnt >= 3:
ans = 1
if ans == 1:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
prev = [arr[0]]
for i in arr[1:]:
prev.append(prev[-1] ^ i)
if prev[-1] == 0:
print("YES")
else:
flag = False
for i in range(n):
if prev[-1] ^ prev[i] == 0:
for j in range(i + 1, n):
if prev[j] == 0:
flag = True
break
if flag:
break
if flag:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | from sys import *
def value_of_arr(a):
result = 0
for x in a:
result = x ^ result
return result
def is_good_arr(a, value):
for x in a:
if x != value:
return False
def check_arr_empty(a, value):
left_value = 0
for i in range(0, len(a) - 1):
x = a[i]
left_value = left_value ^ x
if left_value == value:
return True
return False
def solve_case(t):
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().rstrip().split()]
has_pass = False
all_value = value_of_arr(a)
if all_value == 0:
has_pass = len(a) > 1
else:
left_value = 0
for i in range(0, len(a) - 1):
x = a[i]
left_value = left_value ^ x
if left_value == all_value:
has_pass = check_arr_empty(a[i + 1 :], all_value)
if has_pass:
break
if has_pass:
print("YES")
else:
print("NO")
def main():
T = int(stdin.readline())
for t in range(T):
solve_case(t)
main() | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FUNC_DEF FOR VAR VAR IF VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR IF VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
def f(l, n):
fullxor = l[0]
for i in range(1, n):
fullxor = fullxor ^ l[i]
if fullxor == 0:
return "YES"
else:
var = 0
c = 0
for j in range(n - 1):
var = var ^ l[j]
if var == fullxor:
c = c + 1
var = 0
if c >= 2:
return "YES"
else:
return "NO"
t = int(input())
i = 0
while i != t:
i = i + 1
n = int(input())
x = input().split(" ")
y = [int(o) for o in x]
print(f(y, n)) | IMPORT FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def sol(n, A):
xorlisty = A[0]
for i in range(1, n):
xorlisty ^= A[i]
if xorlisty == 0:
return "YES"
lewa = A[0]
for i in range(1, n):
prawa = A[i]
for j in range(i + 1, n):
if lewa == prawa == xorlisty:
return "YES"
prawa ^= A[j]
lewa ^= A[i]
return "NO"
def main():
for i in range(int(input())):
n = int(input())
print(sol(n, list(map(int, input().split()))))
main() | FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR RETURN STRING VAR VAR VAR VAR VAR VAR RETURN STRING FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | from sys import stdin, stdout
input = stdin.readline
def solve(lis, n):
xor = 0
for i in range(n - 1):
xor ^= lis[i]
j = i + 1
temp_xor = 0
while j < n:
last = -1
while j < n:
temp_xor ^= lis[j]
if temp_xor == xor:
last = j
j += 1
if last == n - 1:
print("YES")
return
if last == -1:
break
j = last + 1
temp_xor = 0
print("NO")
for _ in range(int(input())):
n = int(input())
lis = list(map(int, input().split()))
solve(lis, n) | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def helper(a):
xsum = 0
for i in range(len(a)):
xsum ^= a[i]
if xsum == 0:
return "YES"
t3 = xsum
l = -1
tl = 0
r = len(a)
tr = 0
while l < len(a) - 1:
l += 1
tl ^= a[l]
if tl == t3:
break
while r > 0:
r -= 1
tr ^= a[r]
if tr == t3:
break
if l < r:
return "YES"
else:
return "NO"
t = int(input())
for i in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
res = helper(a)
print(res) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR WHILE VAR NUMBER VAR NUMBER VAR VAR VAR IF VAR VAR IF VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for t in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
xor, count, xorr = 0, 0, 0
for i in range(n):
xor = xor ^ a[i]
if xor == 0:
print("YES")
else:
for i in range(n):
xorr = xorr ^ a[i]
if xor == xorr:
count += 1
xorr = 0
if count >= 2:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve(arr):
ans = 0
for a in arr:
ans ^= a
if ans == 0:
print("YES")
return
s = 0
cnt = 0
for a in arr:
s ^= a
if s == ans:
s = 0
cnt += 1
if s == 0 and cnt > 1:
print("YES")
return
print("NO")
t = int(input())
for _ in range(t):
n = int(input())
arr = [int(x) for x in input().split()]
solve(arr) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
def xor(arr, n):
res = 0
l = 0
y = 0
for i in arr:
res = res ^ i
if res == 0:
return True
for i in arr:
y ^= i
if y == res:
y = 0
l += 1
return l >= 2
for _ in range(t):
n = int(input())
arr = list(map(int, input().split()))
print("YES" if xor(arr, n) else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER RETURN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
while t > 0:
n = int(input())
entrada = input()
array = [int(x) for x in entrada.split(" ")]
ans = 0
for i in range(n):
ans = ans ^ array[i]
if ans == 0:
print("YES")
else:
temp = 0
count = 0
for i in range(n):
temp = temp ^ array[i]
if temp == ans:
count += 1
temp = 0
if temp == 0 and count > 1:
print("YES")
else:
print("NO")
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
def solve(arr, n):
res = 0
for elem in arr:
res ^= elem
if res == 0:
return "YES"
a = 0
for i in range(n):
a ^= arr[i]
if a == res:
break
b = 0
for i in range(i + 1, n):
b ^= arr[i]
if b == res:
break
return "YES" if i != n - 1 else "NO"
def main():
res = ""
input = sys.stdin.readline
print = sys.stdout.write
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
res += solve(a, n) + "\n"
print(res)
main() | IMPORT FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR RETURN VAR BIN_OP VAR NUMBER STRING STRING FUNC_DEF ASSIGN VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
input = lambda: sys.stdin.readline().rstrip()
for _ in range(int(input())):
n = int(input())
A = list(map(int, input().split()))
Result = [0]
for a in A:
Result.append(Result[-1] ^ a)
r = Result[-1]
if not r:
b = 0
else:
idx = Result.index(r)
if idx < n:
S = set(Result[idx + 1 :])
if 0 in S:
b = 0
else:
b = 1
else:
b = 1
print("YNEOS"[b::2]) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR STRING VAR NUMBER |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
input = sys.stdin.buffer.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
p_xor = [0] * n
s_xor = [0] * n
s_xor[-1] = a[-1]
p_xor[0] = a[0]
for i in range(1, n):
p_xor[i] = p_xor[i - 1] ^ a[i]
for i in range(n - 2, -1, -1):
s_xor[i] = s_xor[i + 1] ^ a[i]
triple = 0
for i in range(n):
for j in range(i + 2, n):
if p_xor[i] == s_xor[j] and p_xor[-1] == p_xor[i]:
triple = 1
if triple or p_xor[-1] == 0:
print("YES")
else:
print("NO") | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
input()
l = list(map(int, input().split()))
v = []
for x in l:
if not v:
v.append(x)
else:
v.append(x ^ v[-1])
if v[-1] == 0:
print("YES")
else:
ok = False
for i in range(1, len(l)):
for j in range(i + 1, len(l)):
v1 = v[i - 1]
v2 = v[j - 1] ^ v[i - 1]
v3 = v[-1] ^ v[j - 1]
if v1 == v2 == v3:
print("YES")
ok = True
break
if ok:
break
if not ok:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
a = [int(x) for x in input().split()]
x = 0
for i in a:
x = x ^ i
if x == 0:
print("YES")
else:
arr = [(0) for i in range(31)]
y = 0
f = 0
for i in range(n):
y = y ^ a[i]
if y == x:
f += 1
y = 0
if f < 3:
print("NO")
else:
print("YES") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR 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 VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
N = int(input())
A = list(map(int, input().split()))
setA = list(set(A))
if len(setA) == 1:
print("YES")
elif len(setA) == 2 and (setA[0] == 0 or setA[1] == 0):
print("YES")
else:
u = 0
B = []
for i in A:
u = u ^ i
B.append(u)
if u == 0:
print("YES")
elif A[0] != 0:
e = B[0 : N - 1].count(0)
d = B[0 : N - 1].count(u)
if e > 0 and d > 0 and e == d:
print("YES")
else:
print("NO")
else:
e = B[0 : N - 1].count(0)
d = B[0 : N - 1].count(u)
if e > 1 and d > 0 and e - 1 == d:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER VAR NUMBER NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR IF VAR NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | from sys import stdin, stdout
get_string = lambda: stdin.readline().strip(" ")
get_intmap = lambda: map(int, get_string().split(" "))
def testcase():
n = int(input())
l = list(get_intmap())
dp_left, dp_right = [0] * n, [0] * n
dp_left[0], dp_right[-1] = l[0], l[-1]
for ind in range(1, n):
dp_left[ind] = dp_left[ind - 1] ^ l[ind]
for ind in range(n - 2, -1, -1):
dp_right[ind] = dp_right[ind + 1] ^ l[ind]
for ind in range(n - 1):
if dp_left[ind] == dp_right[ind + 1]:
print("YES")
return
all_xor = dp_left[-1]
dp_left_indices, dp_right_indices = [], []
for ind, val in enumerate(dp_left):
if val == all_xor:
dp_left_indices.append(ind)
for ind, val in enumerate(dp_right):
if val == all_xor:
dp_right_indices.append(ind)
for ind1 in dp_left_indices:
for ind2 in dp_right_indices:
if ind2 > ind1 + 1:
print("YES")
return
print("NO")
t = min(10**9, int(input()))
for t in range(t):
testcase() | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR FOR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
preXor = [0] * n
flag = False
for i in range(n):
if i == 0:
preXor[i] = a[i]
else:
preXor[i] = preXor[i - 1] ^ a[i]
for j in range(n - 1):
if preXor[j] == preXor[n - 1] ^ preXor[j]:
flag = True
break
for i in range(n):
for j in range(i + 1, n - 1):
if (
preXor[i] == preXor[i] ^ preXor[j]
and preXor[i] == preXor[j] ^ preXor[n - 1]
):
flag = True
break
if flag:
break
if flag:
sys.stdout.write("YES" + "\n")
else:
sys.stdout.write("NO" + "\n") | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR EXPR FUNC_CALL VAR BIN_OP STRING STRING EXPR FUNC_CALL VAR BIN_OP STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
a = 0
for x in arr:
a ^= x
c = 0
cnt = 0
for x in arr:
c ^= x
if c == a:
cnt += 1
c = 0
if a == 0 or cnt > 2:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for i in range(t):
n = int(input())
array = [int(j) for j in input().split()]
a = 0
xor = []
for j in range(n):
a = a ^ array[j]
xor.append(a)
if a == 0:
print("YES")
else:
c = xor.index(a)
if 0 in xor[c + 1 :]:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR IF NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | T = int(input())
for t in range(T):
N = int(input())
aa = [int(x) for x in input().split()]
bb = [aa[0]]
for i in range(1, len(aa)):
bb.append(aa[i] ^ bb[i - 1])
if bb[-1] == 0:
print("YES")
else:
last_val = bb[-1]
zero_pos = None
for i in range(len(bb) - 1, -1, -1):
if bb[i] == 0:
zero_pos = i
break
if zero_pos is None:
print("NO")
else:
same_last_pos = None
for i in range(zero_pos - 1, -1, -1):
if bb[i] == last_val:
same_last_pos = i
break
if same_last_pos is None:
print("NO")
else:
print("YES") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def xor(a):
ans = 0
for i in a:
ans ^= i
return ans
def main(a, n):
b = xor(a)
if b == 0:
print("YES")
return ""
else:
main = 0
ct = 0
for i in a:
main ^= i
if main == b:
ct += 1
main = 0
if ct > 1:
print("YES")
return ""
print("NO")
return ""
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
main(a, n) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN STRING EXPR FUNC_CALL VAR STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def fun(ls, n):
if n == 2:
if ls[0] == ls[1]:
print("YES")
else:
print("NO")
else:
prefix_xor = []
for i in ls:
if prefix_xor == []:
prefix_xor.append(i)
else:
prefix_xor.append(i ^ prefix_xor[-1])
array_of_two = False
array_of_three = False
last_xor = prefix_xor[-1]
for i in range(n - 1):
if prefix_xor[i] == last_xor ^ prefix_xor[i]:
array_of_two = True
break
for i in range(n - 2):
for j in range(i + 1, n - 1):
if (
prefix_xor[i] == prefix_xor[j] ^ prefix_xor[i]
and prefix_xor[j] ^ prefix_xor[i] == last_xor ^ prefix_xor[j]
):
array_of_three = True
break
if array_of_two or array_of_three:
print("YES")
else:
print("NO")
T = int(input())
for _ in range(T):
n = int(input())
ls = list(map(int, input().split()))
fun(ls, n) | FUNC_DEF IF VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR LIST FOR VAR VAR IF VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def gift():
for _ in range(t):
n = int(input())
lst = list(map(int, input().split()))
curr = 0
for ele in lst:
curr ^= ele
if curr == 0:
yield "YES"
else:
counter = 0
currC = 0
for ele in lst:
currC ^= ele
if currC == curr:
counter += 1
currC = 0
if counter > 1 and currC == 0:
yield "YES"
else:
yield "NO"
t = int(input())
ans = gift()
print(*ans, sep="\n") | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR STRING EXPR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | from sys import stdin, stdout
input = stdin.readline
def f():
c = -1
x = 0
ok = 0
global val, ans
for j in a:
c += 1
x ^= j
if c == n - 1:
if x == val and ok:
ans = "yes"
if x == val:
ok += 1
x = 0
t = int(input())
for _ in range(t):
n = int(input())
a = [int(x) for x in input().split()]
x = 0
for i in a:
x ^= i
if x == 0:
print("yes")
continue
val = x
ans = "no"
f()
a = a[::-1]
f()
print(ans) | ASSIGN VAR VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR NUMBER IF VAR VAR VAR ASSIGN VAR STRING IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
if len(set(a)) == 1:
print("YES")
continue
rev = a[::-1]
current = rev[0]
check_list = [current]
for x in rev[1:]:
current ^= x
check_list.append(current)
check_list = check_list[::-1][1:]
current = 0
finished = False
for i, x in enumerate(a[:-1]):
current ^= x
if check_list[i] == current:
print("YES")
finished = True
break
if finished:
continue
if n < 3:
print("NO")
continue
c1 = 0
c2 = 0
rest = 0
for x in a:
rest ^= x
for i in range(n - 2):
c1 ^= a[i]
c2 = 0
rest ^= a[i]
c3 = rest + 0
for j in range(i + 1, n - 1):
c2 ^= a[j]
c3 ^= a[j]
if c1 == c2 == c3:
print("YES")
finished = True
break
if finished:
break
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR VAR VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve():
n = int(input())
v = [int(e) for e in input().split()]
x, y, c = 0, 0, 0
for i in range(0, n):
x ^= v[i]
for i in range(n - 1, -1, -1):
y ^= v[i]
if y == x:
c += 1
y = 0
if not x or c > 1:
return "YES"
return "NO"
def init():
T = 1
T = int(input())
while T:
print(solve())
T -= 1
init() | FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def test(N, A):
x = 0
xL = [x]
for a in A:
x = x ^ a
xL.append(x)
if x == 0:
return "YES"
b = False
for i in range(1, N):
x1 = xL[i]
if x1 == x:
for j in range(i + 1, N):
x2 = x1 ^ xL[j]
if x2 == x:
b = True
break
if b:
return "YES"
else:
return "NO"
return xL
for kT in range(int(input())):
N = int(input())
A = list(map(int, input().split()))
print(test(N, A)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER RETURN STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER IF VAR RETURN STRING RETURN STRING RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | I = input
IN = lambda x: map(int, x.split())
L = lambda x: list(IN(x))
for _ in range(int(I())):
n = int(I())
a = L(I())
x = 0
for i in a:
x = x ^ i
if x == 0:
print("YES")
else:
c = 0
y = 0
for i in a:
y = y ^ i
if y == x:
c += 1
y = 0
if c == 2:
print("YES")
break
if c == 1:
print("NO") | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
input = sys.stdin.readline
t = int(input())
for i1 in range(t):
n = int(input())
l = list(map(int, input().split()))
f2 = 0
for i in range(n - 1):
x = 0
for j in range(i + 1):
x = x ^ l[j]
j1 = i + 1
while j1 < n:
y = 0
f = 0
for j2 in range(j1, n):
y = y ^ l[j2]
if y == x:
j1 = j2 + 1
f = 1
if f == 0:
break
if f == 1:
print("YES")
f2 = 1
break
if f2 == 0:
print("NO") | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | n = int(input())
while n != 0:
le = int(input())
lst = list(map(int, input().split()))
x = 0
for i in range(le):
x = lst[i] ^ x
t, c = 0, 0
for i in range(le):
t ^= lst[i]
if t == x:
c += 1
t = 0
if c > 1 or x == 0:
print("YES")
else:
print("NO")
n -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
xor, acc_a, pos0 = 0, [], []
for i in range(n):
xor ^= a[i]
acc_a.append(xor)
if xor == 0:
pos0.append(i)
if xor == 0:
print("YES")
else:
T = len(pos0) > 0 and xor in acc_a[: pos0[-1]]
print("YES" if T else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER LIST LIST FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
def full_xor(a):
res = 0
for ai in a:
res = res ^ ai
return res
for _ in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
res = 0
xors = []
for ai in a:
res = res ^ ai
xors.append(res)
if res != 0:
if xors.count(res) > 1:
first = xors.index(res)
new = xors[first:]
if 0 in new:
res = 0
if xors.count(res) > 1:
first = xors.index(res)
second = first + 1 + xors[first + 1 :].index(res)
new = a[second + 1 :]
if full_xor(new) == res:
res = 0
print("YES" if res == 0 else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF NUMBER VAR ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
s = 0
for x in a:
s ^= x
if s == 0:
print("YES")
else:
cnt = 0
i = 0
t = 0
while i < n:
t ^= a[i]
i += 1
if t == s:
t = 0
cnt += 1
if t != 0 or cnt == 1:
print("NO")
else:
print("YES") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
l = list(map(int, input().split()))
c = []
for i in l:
if i != 0:
c.append(i)
flag = 0
for i in range(len(c)):
f = -1
for j in range(i + 1):
if f == -1:
f = c[j]
else:
f = f ^ c[j]
s = -1
for j in range(i + 1, len(c)):
if s == -1:
s = c[j]
else:
s = s ^ c[j]
if f == s and j < len(c) - 1:
s = -1
if f == s:
flag = 1
break
if flag:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve():
n = int(input())
arr = list(map(int, input().split()))
count = 0
x = 0
for i in arr:
x ^= i
if x == 0:
print("YES")
return
nx = 0
for i in arr:
nx ^= i
if nx == x:
count += 1
nx = 0
if count >= 3:
print("YES")
else:
print("NO")
def main():
t = int(input())
while t:
solve()
t -= 1
main() | 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 ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
c = 0
for i in range(n - 1):
x = 0
for j in range(i + 1):
x = x ^ a[j]
f1 = 0
t = 0
for j in range(i + 1, n):
t = t ^ a[j]
if t == x:
f1 = 1
t = 0
if t == 0 and f1:
c = 1
break
if c == 1:
print("YES")
if c == 0:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
xor = a[0]
for i in range(1, n):
xor ^= a[i]
if xor == 0:
print("YES")
else:
currxor = 0
totxor = xor
cnt = 0
for i in range(n):
currxor ^= a[i]
totxor ^= a[i]
remxor = totxor ^ xor
if currxor == xor and i != n - 1:
cnt += 1
if cnt > 1 and remxor == 0:
break
currxor = 0
if currxor == xor and cnt > 0:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def win(lst):
count = 0
x = 0
for i in range(n):
x = x ^ lst[i]
if x == 0:
print("YES")
return
else:
k = 0
for i in range(n):
k ^= lst[i]
if k == x:
k = 0
count += 1
if count >= 2:
print("YES")
else:
print("NO")
t = int(input())
while t:
n = int(input())
lst = list(map(int, input().split()))
win(lst)
t -= 1 | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 VAR VAR NUMBER |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
pfx = []
xor = 0
lst = -1
for i in range(n):
xor ^= ar[i]
pfx.append(xor)
if pfx[-1] == 0:
print("YES")
continue
else:
x = pfx[-1]
cnt, temp = 0, 0
for i in range(n):
temp = temp ^ ar[i]
if temp == x:
cnt += 1
temp = 0
if cnt >= 3:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
def main():
t = int(input())
allans = []
for _ in range(t):
n = int(input())
a = readIntArr()
suffixXor = [(-1) for _ in range(n)]
x = 0
for i in range(n - 1, -1, -1):
x ^= a[i]
suffixXor[i] = x
ans = "NO"
px = 0
prevXors = set()
for i in range(n - 1):
px ^= a[i]
s = suffixXor[i + 1]
if px == s:
ans = "YES"
break
if px == 0 and s in prevXors:
ans = "YES"
break
prevXors.add(px)
allans.append(ans)
multiLineArrayPrint(allans)
return
input = sys.stdin.buffer.readline
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultVal, dimensionArr):
dv = defaultVal
da = dimensionArr
if len(da) == 1:
return [dv for _ in range(da[0])]
else:
return [makeArr(dv, da[1:]) for _ in range(da[0])]
def queryInteractive(x, y):
print("? {} {}".format(x, y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(ans))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR STRING IF VAR NUMBER VAR VAR ASSIGN VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve() -> bool:
n = int(input())
array = list(map(int, input().split()))
s = 0
for e in array:
s ^= e
if s == 0:
return True
current = 0
counter = 0
for e in array:
current ^= e
if current == s:
counter += 1
current = 0
if counter > 2:
return True
return False
for _ in range(int(input())):
print("YES" if solve() else "NO") | 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 VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve(arr):
n = len(arr)
if arr[-1] == 0:
return "YES"
for i in range(n - 2):
if arr[i] == arr[-1]:
for j in range(i + 1, n - 1):
if arr[j] == 0:
return "YES"
return "NO"
T = int(input())
for _ in range(T):
n = int(input())
a = [int(x) for x in input().split()]
xor = a[0]
xors = [xor]
for x in a[1:]:
xor ^= x
xors.append(xor)
result = solve(xors)
print(result) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER RETURN STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | T = int(input())
for t in range(T):
n = int(input())
a = list(map(int, input().split()))
x = a[0]
acc_a = [x]
i = 1
while i < n and x ^ a[i] != 0:
x = x ^ a[i]
acc_a.append(x)
i += 1
if i == n:
print("NO")
elif i == n - 1:
print("YES")
else:
y = 0
for j in range(i + 1, n):
y = y ^ a[j]
if y == 0:
print("YES")
else:
z = 0
flag = False
for k in reversed(range(1, i + 1)):
z = z ^ a[k]
if z == y and acc_a[k - 1] == y:
flag = True
break
print("YES" if flag else "NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR NUMBER WHILE VAR VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR STRING STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
xor = 0
for i in range(n):
xor ^= a[i]
if xor == 0:
print("YES")
else:
xort = 0
i = 0
while i < n - 1:
xort ^= a[i]
if xort == xor:
break
i += 1
if i == n - 2:
print("NO")
else:
xort = 0
i = i + 1
while i < n:
xort ^= a[i]
if xort == xor:
break
i += 1
if i == n - 1:
print("NO")
else:
xort = 0
i += 1
while i < n:
xort ^= a[i]
i += 1
if xort == xor:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
li = list(map(int, input().split()))
x = 0
c = []
for i in li:
x = x ^ i
c.append(x)
c.pop()
if x == 0:
print("YES")
elif x in c and 0 in c and c.index(x) < c.index(0):
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
nimsum = 0
for val in a:
nimsum ^= val
if nimsum == 0:
print("YES")
continue
front_xor = 0
front_id = None
for i in range(n):
front_xor ^= a[i]
if front_xor == nimsum:
front_id = i
break
back_xor = 0
back_id = None
for i in range(n - 1, -1, -1):
back_xor ^= a[i]
if back_xor == nimsum:
back_id = i
break
if front_id >= back_id:
print("NO")
continue
print("YES") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
x = 0
count = 0
for i in range(n):
x = x ^ l[i]
if x == 0:
print("YES")
else:
i = 0
count = 0
while i < n - 1:
if l[i] == x:
i += 1
count += 1
else:
p = l[i] ^ l[i + 1]
l[i] = 0
l[i + 1] = p
i += 1
q = list(set(l))
q.sort()
if len(q) > 2:
print("NO")
elif count < 2:
print("NO")
elif len(q) == 2:
if q[0] == 0 and q[1] == x:
print("YES")
else:
print("NO")
elif q[0] == x:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for i in range(t):
n = int(input())
line = input()
nums = line.split(" ")
last = 0
for j in range(0, n):
last = last ^ int(nums[j])
if last == 0:
print("YES")
continue
xor = last
last = 0
count = 0
for i in range(0, n):
last ^= int(nums[i])
if last == xor:
count += 1
last = 0
if count >= 3:
print("YES")
continue
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve(arr, n):
if n == 2:
if arr[0] == arr[-1]:
return "YES"
else:
return "NO"
x = 0
for it in arr:
x ^= it
if x == 0:
pref = 0
for it in arr[:-1]:
pref ^= it
if pref == x ^ pref:
return "YES"
return "NO"
count = 0
cur = 0
for it in arr:
cur ^= it
if cur == x:
count += 1
cur = 0
if count > 1 and cur == 0:
return "YES"
else:
return "NO"
for case in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
ans = solve(arr, n)
print(ans) | FUNC_DEF IF VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR NUMBER VAR VAR IF VAR BIN_OP VAR VAR RETURN STRING RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER RETURN STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve(a1, a2, n):
for i in range(n - 1):
if a1[i] == a2[i + 1]:
return "YES"
for i in range(n - 1):
if a2[i + 1] == 0:
x = a1[i]
for j in range(i + 1, n):
if a2[j] == x:
return "YES"
return "NO"
t = int(input())
for j in range(t):
n = int(input())
arr = list(map(int, input().split(" ")))
prearr = []
postarr = []
for i in range(n):
prearr.append(arr[i])
postarr.append(arr[i])
for i in range(1, n):
prearr[i] = prearr[i - 1] ^ arr[i]
for i in range(n - 2, -1, -1):
postarr[i] = postarr[i + 1] ^ arr[i]
print(solve(prearr, postarr, n)) | FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def proB(arr):
k = 0
for i in range(len(arr) - 1):
k = k ^ arr[i]
j = i + 1
k2 = 0
lst = []
while j < len(arr):
k2 = k2 ^ arr[j]
if k2 == k:
lst.append(k2)
k2 = 0
j += 1
if k2 == 0 and k in lst:
print("YES")
return
print("NO")
return
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
proB(arr) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def solve(n, A):
f = []
b = []
t = 0
for a in A:
t = t ^ a
f.append(t)
t = 0
for a in A[::-1]:
t = t ^ a
b.append(t)
b = b[::-1]
table = [([0] * n) for i in range(n)]
for i in range(n - 1):
t = 0
for j in range(i, n):
t = t ^ A[j]
table[i][j] = t
for i in range(n - 1):
if f[i] == b[i + 1]:
return "YES"
for i in range(n - 2):
for j in range(i, n - 1):
if f[i] == b[j + 1] and f[i] == table[i + 1][j]:
return "YES"
return "NO"
def main():
ans = []
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split(" ")))
ans.append(solve(n, a))
for a in ans:
print(a)
main() | FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN STRING RETURN STRING FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | def ans(l, n):
xr, x = 0, 0
for i in range(n):
xr ^= l[i]
if xr == 0:
return "YES"
for i in range(n):
x ^= l[i]
c = 0
if x == xr:
for j in range(i + 1, n - 1):
c ^= l[j]
if c == x:
return "YES"
return "NO"
tc = int(input())
for _ in range(tc):
n = int(input())
l = list(map(int, input().split()))
print(ans(l, n)) | FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN STRING FOR VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR VAR RETURN STRING RETURN STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for s in [*open(0)][2::2]:
a = [0]
for x in s.split():
a += (a[-1] ^ int(x),)
print("NYOE S"[0 in a[a.index(a[-1]) :] :: 2]) | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for s in [*open(0)][2::2]:
a = (*map(int, s.split()),)
b = [0]
i = 0
for x in a:
b += (b[-1] ^ x,)
print("NYOE S"[0 in b[b.index(b[-1]) :] :: 2]) | FOR VAR LIST FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING NUMBER VAR FUNC_CALL VAR VAR NUMBER NUMBER |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
l = list(map(int, input().split()))
pre = [-1] * n
pre[0] = l[0]
for i in range(1, n):
pre[i] = l[i] ^ pre[i - 1]
flag = False
for i in range(n - 1):
if pre[i] == pre[n - 1] ^ pre[i]:
flag = True
break
if not flag:
for i in range(n - 2):
start = pre[i]
for j in range(i + 1, n - 1):
mid = pre[j] ^ pre[i]
end = pre[n - 1] ^ pre[j]
if start == mid and mid == end:
flag = True
break
if flag:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
s = a[0]
for i in range(1, n):
s = s ^ a[i]
if s == 0:
print("YES")
else:
s = a[0]
c = 0
for i in range(1, n):
s = s ^ a[i]
if s == 0:
c = i
break
s = 0
for i in range(c + 1, n):
s = s ^ a[i]
d = 0
z = 0
for i in range(c + 1):
d = d ^ a[i]
if d == s:
z += 1
d = 0
if z == 2 and d == 0:
print("YES")
else:
print("NO") | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL 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 ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | t = int(input())
for _ in range(t):
n = int(input())
a = [int(s) for s in input().split(" ")]
x = y = c = 0
for s in a:
x ^= s
for s in a:
y ^= s
if y == x:
c += 1
y = 0
if c > 1 or x == 0:
print("YES")
else:
print("NO") | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR VAR NUMBER FOR VAR VAR VAR VAR FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
def solve(n, a):
b = a[:]
for i in range(1, n):
b[i] ^= b[i - 1]
def X(i, j):
if i == 0:
return b[j]
return b[j] ^ b[i - 1]
seen = set()
for i in range(n - 1):
cur = b[i]
x = X(i + 1, n - 1)
if cur == x:
return "YES"
if x in seen and cur ^ x == x:
return "YES"
seen.add(cur)
return "NO"
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
print(solve(n, a)) | IMPORT FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR VAR RETURN BIN_OP VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR RETURN STRING IF VAR VAR BIN_OP VAR VAR VAR RETURN STRING EXPR FUNC_CALL VAR VAR RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Baby Ehab is known for his love for a certain operation. He has an array $a$ of length $n$, and he decided to keep doing the following operation on it:
he picks $2$ adjacent elements; he then removes them and places a single integer in their place: their bitwise XOR . Note that the length of the array decreases by one.
Now he asks you if he can make all elements of the array equal. Since babies like to make your life harder, he requires that you leave at least $2$ elements remaining.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 15$) β the number of test cases you need to solve.
The first line of each test case contains an integers $n$ ($2 \le n \le 2000$) β the number of elements in the array $a$.
The second line contains $n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($0 \le a_i < 2^{30}$) β the elements of the array $a$.
-----Output-----
If Baby Ehab can make all elements equal while leaving at least $2$ elements standing, print "YES". Otherwise, print "NO".
-----Examples-----
Input
2
3
0 2 2
4
2 3 1 10
Output
YES
NO
-----Note-----
In the first sample, he can remove the first $2$ elements, $0$ and $2$, and replace them by $0 \oplus 2=2$. The array will be $[2,2]$, so all the elements are equal.
In the second sample, there's no way to make all the elements equal. | import sys
input = sys.stdin.readline
def solve():
n = int(input())
arr = list(map(int, input().split()))
V = 0
for i in range(n):
V ^= arr[i]
if V > 0:
curr = cnt = 0
for i in range(n):
curr ^= arr[i]
if curr == V:
cnt += 1
curr = 0
return "YES" if cnt % 2 and cnt > 2 else "NO"
else:
return "YES"
for _ in range(int(input())):
print(solve()) | 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 ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER STRING STRING RETURN STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
input = lambda: sys.stdin.readline().rstrip()
def dr_evil(a, l):
b0 = []
b1 = []
for i in a:
if i & 1 << l:
b1.append(i)
else:
b0.append(i)
if len(b0) == 0:
if l == 0:
return 0
else:
return dr_evil(b1, l - 1)
elif len(b1) == 0:
if l == 0:
return 0
else:
return dr_evil(b0, l - 1)
else:
if l == 0:
return 1
return min(dr_evil(b0, l - 1), dr_evil(b1, l - 1)) + (1 << l)
n = int(input())
A = [int(i) for i in input().split()]
l = max(A).bit_length()
if l == 0:
print(0)
else:
print(dr_evil(A, l - 1)) | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP 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 FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | def recur(arr, val, pos):
if pos == -1:
return val
on = []
off = []
for i in arr:
if i & 1 << pos:
on.append(i)
else:
off.append(i)
if on and off:
return min(
recur(on, val + (1 << pos), pos - 1), recur(off, val + (1 << pos), pos - 1)
)
elif on:
return recur(on, val, pos - 1)
else:
return recur(off, val, pos - 1)
n = int(input())
arr = [int(x) for x in input().split()]
print(recur(arr, 0, 31)) | FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER 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 NUMBER NUMBER |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
def main():
n = int(input())
a = readIntArr()
def dfs(arr, bitShift):
if bitShift == -1:
return 0
zeroes = []
ones = []
for x in arr:
if x & 1 << bitShift > 0:
ones.append(x)
else:
zeroes.append(x)
if ones and zeroes:
return 1 << bitShift | min(
dfs(ones, bitShift - 1), dfs(zeroes, bitShift - 1)
)
elif ones:
return dfs(ones, bitShift - 1)
else:
return dfs(zeroes, bitShift - 1)
ans = dfs(a, 29)
print(ans)
return
input = sys.stdin.buffer.readline
def oneLineArrayPrint(arr):
print(" ".join([str(x) for x in arr]))
def multiLineArrayPrint(arr):
print("\n".join([str(x) for x in arr]))
def multiLineArrayOfArraysPrint(arr):
print("\n".join([" ".join([str(x) for x in y]) for y in arr]))
def readIntArr():
return [int(x) for x in input().split()]
def makeArr(defaultVal, dimensionArr):
dv = defaultVal
da = dimensionArr
if len(da) == 1:
return [dv for _ in range(da[0])]
else:
return [makeArr(dv, da[1:]) for _ in range(da[0])]
def queryInteractive(x, y):
print("? {} {}".format(x, y))
sys.stdout.flush()
return int(input())
def answerInteractive(ans):
print("! {}".format(ans))
sys.stdout.flush()
inf = float("inf")
MOD = 10**9 + 7
for _abc in range(1):
main() | IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL STRING FUNC_CALL VAR VAR VAR VAR VAR VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN VAR VAR FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR NUMBER FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR VAR EXPR FUNC_CALL VAR RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
def solve(a, l):
bit0 = []
bit1 = []
for elem in a:
if elem & 1 << l:
bit1.append(elem)
else:
bit0.append(elem)
if len(bit0) == 0:
if l == 0:
return 0
else:
return solve(bit1, l - 1)
elif len(bit1) == 0:
if l == 0:
return 0
else:
return solve(bit0, l - 1)
elif l == 0:
return 1
else:
return min(solve(bit1, l - 1), solve(bit0, l - 1)) + (1 << l)
l = max(a).bit_length()
if l == 0:
print(0)
else:
print(solve(a, l - 1)) | 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 FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
n = int(input())
a = list(map(int, input().split()))
a.sort()
stack = [(0, n, 1 << 29, 0)]
ans = 1 << 30
while stack:
l, r, mask, curr = stack.pop()
if not mask:
ans = min(ans, curr)
elif not a[l] & mask and a[r - 1] & mask:
L = l
R = r - 1
while L + 1 < R:
m = L + R >> 1
if a[m] & mask:
R = m
else:
L = m
m = R
stack.append((l, m, mask >> 1, curr | mask))
stack.append((m, r, mask >> 1, curr | mask))
else:
stack.append((l, r, mask >> 1, curr))
print(ans) | IMPORT ASSIGN VAR FUNC_CALL VAR VAR VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF BIN_OP VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | n = int(input())
A = [int(s) for s in input().split()]
A.sort()
maxA = -1
for a in A:
maxA = max(maxA, a)
priMask = 1
while priMask <= maxA:
priMask <<= 1
def recur(start, end, mask):
if mask == 0:
return 0
if A[start] & mask or not A[end] & mask:
return recur(start, end, mask >> 1)
low = start
high = end
while high - low > 1:
mid = (low + high) // 2
if A[mid] & mask:
high = mid
else:
low = mid
leftMin = recur(start, low, mask >> 1)
rightMin = recur(high, end, mask >> 1)
return mask + min(leftMin, rightMin)
ans = recur(0, n - 1, priMask)
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN NUMBER IF BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | def get_x(i, nums):
get_ith_bit = lambda num: num >> i & 1
hi, lo = [], []
for num in nums:
(hi if get_ith_bit(num) == 1 else lo).append(num)
if hi and lo:
if i == 0:
return 1
ith_bit = 1 << i
explore_hi = get_x(i - 1, hi)
explore_lo = get_x(i - 1, lo)
next_bits = min(explore_hi, explore_lo)
else:
if i == 0:
return 0
ith_bit = 0
next_bits = get_x(i - 1, nums)
return ith_bit | next_bits
input()
nums = [int(n) for n in input().split()]
print(get_x(30, nums)) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR LIST LIST FOR VAR VAR EXPR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR RETURN BIN_OP VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
X = int(sys.stdin.readline())
a = set([int(i) for i in sys.stdin.readline().split()])
top = 1 << 31
ans = 0
def best(s, cur):
if len(s) == 0 or cur == 0:
return 0
hasCur = set()
hasNotCur = set()
for i in s:
if i & cur == 0:
hasNotCur.add(i)
else:
hasCur.add(i)
if len(hasNotCur) == 0 or len(hasCur) == 0:
return best(s, cur >> 1)
else:
return cur + min(best(hasNotCur, cur >> 1), best(hasCur, cur >> 1))
print(best(a, top)) | IMPORT 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 BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN 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 RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
def f(a, bit):
if len(a) == 0 or bit < 0:
return 0
l, r = list(), list()
x = 1 << bit
for i in a:
if x & i > 0:
r.append(i)
else:
l.append(i)
if len(l) == 0:
return f(r, bit - 1)
if len(r) == 0:
return f(l, bit - 1)
return min(f(l, bit - 1), f(r, bit - 1)) + x
def main():
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
print(f(a, 30))
main() | IMPORT FUNC_DEF IF FUNC_CALL VAR VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR 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 IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | n = int(input())
lis = list(map(int, input().split()))
def dfs(arr, pos):
if pos < 0 or len(arr) == 0:
return 0
l1 = []
l2 = []
for i in arr:
if i >> pos & 1 == 0:
l1.append(i)
else:
l2.append(i)
if not l1:
return dfs(l2, pos - 1)
elif not l2:
return dfs(l1, pos - 1)
else:
return min(dfs(l1, pos - 1), dfs(l2, pos - 1)) + (1 << pos)
print(dfs(lis, 30)) | 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 FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | def solve(nums: set, bit: int):
if len(nums) == 1:
return 0
lo = {x for x in nums if x & bit}
hi = nums - lo
if not lo:
return solve(hi, bit >> 1)
if not hi:
return solve(lo, bit >> 1)
return bit + min(solve(lo, bit >> 1), solve(hi, bit >> 1))
input()
nums = set(map(int, input().split()))
print(solve(nums, 1 << 30)) | FUNC_DEF VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR 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 BIN_OP NUMBER NUMBER |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
input = sys.stdin.readline
n = int(input())
l = [int(i) for i in input().split()]
ans = 0
def xorchecker(l, ans, pow_):
if pow_ == -1:
return ans
one = []
zero = []
for i in l:
if i & 1 << pow_ != 0:
one.append(i)
else:
zero.append(i)
if zero == [] or one == []:
return xorchecker(l, ans, pow_ - 1)
else:
return min(
xorchecker(zero, ans + (1 << pow_), pow_ - 1),
xorchecker(one, ans + (1 << pow_), pow_ - 1),
)
print(xorchecker(l, ans, 30)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF IF VAR NUMBER RETURN VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR LIST VAR LIST RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | n = int(input())
L = list(map(int, input().split()))
def solve(L, k):
if k == 0:
if 0 in L and 1 in L:
return 1
else:
return 0
bit = 2**k
L0 = []
L1 = []
for i in L:
if i >= bit:
L1.append(i - bit)
else:
L0.append(i)
if L0 == []:
return solve(L1, k - 1)
if L1 == []:
return solve(L0, k - 1)
sol0 = solve(L0, k - 1)
sol1 = solve(L1, k - 1)
return min(sol0, sol1) + bit
m = max(L)
t = 1
count = 0
while m > 1:
m //= 2
count += 1
print(solve(L, count)) | 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 IF NUMBER VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR IF VAR LIST RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR LIST RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
INF = 10**10
def main():
n = get_int()
li = get_list()
binaries = [bin(i)[2:].zfill(30) for i in li]
def solve(li, lvl):
if lvl == 30:
return ""
l1, l2 = [], []
for i in li:
if binaries[i][lvl] == "0":
l1.append(i)
else:
l2.append(i)
if len(l1) == 0:
return "0" + solve(l2, lvl + 1)
elif len(l2) == 0:
return "0" + solve(l1, lvl + 1)
else:
return "1" + min(solve(l1, lvl + 1), solve(l2, lvl + 1))
print(int(solve(range(n), 0), 2))
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main() | IMPORT ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR FUNC_DEF IF VAR NUMBER RETURN STRING ASSIGN VAR VAR LIST LIST FOR VAR VAR IF VAR VAR VAR STRING EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER RETURN BIN_OP STRING FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP STRING FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | n = int(input())
a = list(map(int, input().split()))
maxim = cum = ans = 0
bitmask = 1
for ai in a:
maxim = max(maxim, ai)
while bitmask <= maxim:
bitmask <<= 1
bitmask >>= 1
consider = [1] * len(a)
while bitmask > 0:
dic = {}
for i in range(len(a)):
if consider[i] == 0:
continue
if cum & a[i] not in dic.keys():
dic[cum & a[i]] = a[i] & bitmask
if dic[cum & a[i]] != a[i] & bitmask:
dic[cum & a[i]] = -1
to_pop = []
for key in dic.keys():
if dic[key] == -1:
to_pop.append(key)
for key in to_pop:
dic.pop(key)
if bool(dic):
for i in range(len(a)):
if consider[i] and cum & a[i] not in dic.keys():
consider[i] = 0
else:
ans += bitmask
cum |= bitmask
bitmask >>= 1
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR WHILE VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR WHILE VAR NUMBER ASSIGN VAR DICT FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF BIN_OP VAR VAR VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
sys.setrecursionlimit(10**9)
n = int(input())
a = list(map(int, input().split()))
def calc(lis, keta):
mask = 1 << keta
one = []
zer = []
for ai in lis:
if mask & ai:
one.append(ai)
else:
zer.append(ai)
if keta == 0:
if len(one) * len(zer) == 0:
return 0
else:
return 1
else:
ret = 0
if len(one) * len(zer) != 0:
ret += mask
ret += min(calc(one, keta - 1), calc(zer, keta - 1))
elif one:
ret = calc(one, keta - 1)
else:
ret = calc(zer, keta - 1)
return ret
ans = calc(a, 31)
print(ans) | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER 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 BIN_OP NUMBER 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 NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
Today, as a friendship gift, Bakry gave Badawy $n$ integers $a_1, a_2, \dots, a_n$ and challenged him to choose an integer $X$ such that the value $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$ is minimum possible, where $\oplus$ denotes the bitwise XOR operation.
As always, Badawy is too lazy, so you decided to help him and find the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Input-----
The first line contains integer $n$ ($1\le n \le 10^5$).
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 2^{30}-1$).
-----Output-----
Print one integer β the minimum possible value of $\underset{1 \leq i \leq n}{\max} (a_i \oplus X)$.
-----Examples-----
Input
3
1 2 3
Output
2
Input
2
1 5
Output
4
-----Note-----
In the first sample, we can choose $X = 3$.
In the second sample, we can choose $X = 5$. | import sys
input = sys.stdin.readline
def find(a, x, j, p):
d = []
e = []
if j < 0:
return x
for i in range(len(a)):
if a[i] & 1 << j:
d.append(a[i])
else:
e.append(a[i])
if len(e) == 0:
x = find(d, x, j - 1, p)
elif len(d) == 0:
x = find(e, x, j - 1, p)
else:
x = min(find(e, x, j - 1, p), find(d, x, j - 1, p)) | 1 << j
return x
n = int(input())
a = [int(x) for x in input().split()]
print(find(a, 0, len(bin(max(a))[2:]), a)) | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST IF VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR BIN_OP NUMBER 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 NUMBER FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.