Problem:


Score : 300 points

Problem Statement

Snuke has N hats. The i-th hat has an integer a_i written on it.

There are N camels standing in a circle.
Snuke will put one of his hats on each of these camels.

If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print Yes; otherwise, print No.

The bitwise XOR of the numbers written on the hats on both adjacent camels is equal to the number on the hat on itself.

What is XOR?

The bitwise XOR x_1 \oplus x_2 \oplus \ldots \oplus x_n of n non-negative integers x_1, x_2, \ldots, x_n is defined as follows:

- When x_1 \oplus x_2 \oplus \ldots \oplus x_n is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if the number of integers among x_1, x_2, \ldots, x_n whose binary representations have 1 in the 2^k's place is odd, and 0 if that count is even.

For example, 3 \oplus 5 = 6.

Constraints

All values in input are integers.

3 \leq N \leq 10^{5}

0 \leq a_i \leq 10^{9}

Input

Input is given from Standard Input in the following format:

N
a_1 a_2 \ldots a_{N}

Output

Print the answer.

Sample Input 1

3
1 2 3

Sample Output 1

Yes

If we put the hats with 1, 2, and 3 in this order, clockwise, the condition will be satisfied for every camel, so the answer is Yes.

Sample Input 2

4
1 2 4 8

Sample Output 2

No

There is no such way to distribute the hats; the answer is No.



Sample input:
3
1 2 3


Sample output:
Yes

Submission status: Wrong Answer

Solution code:

import numpy as np 

def make_bit(A):
    arr = np.zeros(31)
    i = 30
    while A:
        arr[i] = A % 2
        A = A // 2
        i -= 1

    return arr

def return_first_second_third(a_lst):
    first = [a_lst[0], 0]
    second = [-1, -1]
    third = [-1, -1]
    i = 0
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            second[0] = a_lst[i+1]
            second[1] = i+1
            i += 1
            break
        else:
            i += 1
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            third[0] = a_lst[i+1]
            third[1] = i+1
            i += 1
            break
        else:
            i += 1
    
    return first, second, third


N = int(input())

a_lst = list(map(int, input().split()))
a_lst.sort()
first, second, third = return_first_second_third(a_lst)
a_lst.reverse()

done = False
if second[0] == -1: # 全ての数が同じとき
    done = True
    if first[0] == 0: # 全ての数がゼロの時
        print("Yes")
    else:
        print("No")
elif third[0] == -1:    # 数が2種類だけの時
    done = True
    if N % 2 == 0 and second[1] == N // 2 and first[1] == 0:
        print("Yes")
    else:
        print("No")
elif N % 3 == 0 and N != 3 and second[1] == N // 3 and third[1] == N * 2 // 3:
    a_lst = [ a_lst[0] + a_lst[second[1]] + a_lst[third[1]] ]


if not done:
    if N == 3:

        a1 = make_bit(a_lst[0])
        a2 = make_bit(a_lst[1])
        a3 = make_bit(a_lst[2])
        bits_arr = np.array([a1, a2, a3])

        judge = True
        for i in range(31):
            if bits_arr[0][i] == bits_arr[1][i] and bits_arr[2][i] == 1:
                judge = False
                break

            elif bits_arr[0][i] != bits_arr[1][i] and bits_arr[2][i] == 0:
                judge = False
                break
                
        if judge:
            print("Yes")
        else:
            print("No")


    else:
        print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=set(a)
l=len(b)
if l==2:
  c=sorted([b.pop(),b.pop()])
  if c[1]^c[0]==c[1]:
    if n%2==0 and a[n//3-1]!=a[n//3]:print("Yes")
    else:print("No")
  else:print("No")
  exit()
elif l==1:
  if a[0]==0:print("Yes")
  else:print("No")
  exit()
elif l!=3:print("No");exit()
if n%3!=0:print("No");exit()
if b.pop()^b.pop()^b.pop()!=0:print("No");exit()
m=n//3
if a[m-1]!=a[m]and a[m*2-1]!=a[m*2]:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

a = list(map(int, input().split()))

a_coll  = collections.Counter(a)
a_key   = list(a_coll.keys())
a_value = list(a_coll.values())

if N % 3 != 0:
    if len(a_key) == 1 and a_key[0] == 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(a_key) == 1:
    if a_key[0] == 0:
        print("Yes")
        exit()

if len(a_key) == 2:
    if 0 in a_key:
        print("Yes")
        exit()

for count in a_value:
    if count != int(N / 3):
        print("No")
        exit()

if len(a_key) == 3:
    if a_key[0] ^ a_key[1] == a_key[2]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_2=[]
for i in range(len(a)):
    a_2.append(bin(a[i]))
import collections
c = collections.Counter(a_2)
b=[]
out=0
for i in c.values():
    b.append(i)
if a.count(0)==0:#0がない場合
    if len(b)!=3:
        out=1
    elif b[0]!=b[1] or b[1]!=b[2]:
        out=1
    elif (b[0]^b[1]^b[2])==0:
        out=0
    else:out=1
else:#0あり
    if len(b)>2:
        out=1
    elif len(b)==1:
        pass
    elif len(b)==2:
        if a.count(0)*3==len(a):
            pass
        else:
            out=1
if out==0:
    print('Yes')
elif out==1:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    num = int(input())
    data = list(map(int, input().split()))

    num_c = Counter(data)
    if len(num_c) > 3:
        print('No')
    else:
        if len(num_c) == 1:
            if sum(num_c.keys()) == 0:
                print('Yes')
            else:
                print('No')
        elif len(num_c) == 2:
            if num_c[0] == num // 3:
                print('Yes')
            else:
                print('No')
        else:
            ans = 0
            for ele in num_c.keys():
                ans ^= ele
            if ans == 0:
                print('Yes')
            else:
                print('No')







if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

a = list(map(int, input().split()))

a_coll  = collections.Counter(a)
a_key   = list(a_coll.keys())
a_value = list(a_coll.values())

if N % 3 != 0:
    if len(a_key) == 1 and a_key[0] == 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(a_key) == 1:
    if a_key[0] == 0:
        print("Yes")
        exit()

if len(a_key) == 2:
    if 0 in a_key:
        print("Yes")
        exit()

for count in zip(a_value):
    if count != int(N / 3):
        print("No")
        exit()

if len(a_key) == 3:
    if a_key[0] ^ a_key[1] == a_key[2]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_2=[]
for i in range(len(a)):
    a_2.append(bin(a[i]))
import collections
c = collections.Counter(a_2)
b=[]
out=0
for i in c.values():
    b.append(i)
if a.count(0)==0:#0がない場合
    if len(b)!=3:
        out=1
    elif b[0]!=b[1] or b[1]!=b[2]:
        out=1
    elif (b[0]^b[1]^b[2])==0:
        out=0
else:#0あり
    if len(b)>2:
        out=1
    elif len(b)==1:
        pass
    elif len(b)==2:
        if a.count(0)*3==len(a):
            pass
        else:
            out=1
if out==0:
    print('Yes')
elif out==1:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
a_list = list(map(int, input().split()))

f = True

a_list.sort()

for i in range(N):
    a1 = a_list[i]
    a2 = a_list[(i + 1) % N]
    a3 = a_list[(i + 2) % N]
    if a1 ^ a3 == a2:
        continue
    else:
        f = False

if f:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if(A.count(0) != 0):
    if(A.count(0) == N):
        print('Yes')
    elif(A.count(0) == int((N - 2)/3) + 1):
        a = -1
        b = -1
        aa = 0
        a = A.count(aa)

        bb = -1

        for i in A:
            if(aa != i):
                bb = i
                break
        if(bb != -1):
            b = A.count(bb)
            if(a + b == N):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    if(N % 3 == 0):
        a = -1
        b = -1
        c = -1
        aa = A[0]
        a = A.count(aa)

        bb = -1

        for i in A:
            if(aa != i):
                bb = i
                break
        if(bb != -1):
            b = A.count(bb)
            if(a == b):
                cc = -1

                for i in A:
                    if(aa != i and bb != i):
                        cc = i
                        break
                if(cc != -1):
                    c = A.count(cc)
                    if(b == c and a + b + c == N):
                        print('Yes')
                    else:
                        print('No')
                else:
                    print('No')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if  a[i-1] ^ a[i] in a_ :
            # a_.discard(a[i-1] ^ a[i])
            pass
        else:
            count += 1

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if(A.count(0) != 0):
    if(A.count(0) == N):
        print('Yes')
    elif(A.count(0) == int((N - 2)/3) + 1 or A.count(0) == N /3):
        a = -1
        b = -1
        aa = 0
        a = A.count(aa)

        bb = -1

        for i in A:
            if(aa != i):
                bb = i
                break
        if(bb != -1):
            b = A.count(bb)
            if(a + b == N):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    if(N % 3 == 0):
        a = -1
        b = -1
        c = -1
        aa = A[0]
        a = A.count(aa)

        bb = -1

        for i in A:
            if(aa != i):
                bb = i
                break
        if(bb != -1):
            b = A.count(bb)
            if(a == b):
                cc = -1

                for i in A:
                    if(aa != i and bb != i):
                        cc = i
                        break
                if(cc != -1):
                    c = A.count(cc)
                    if(b == c and a + b + c == N):
                        print('Yes')
                    else:
                        print('No')
                else:
                    print('No')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
a=set(a_list)
a=list(a)
if 0 in a:
        if len(a) ==2:
            if a_list.count(0)==len(a_list)//3 or a_list.count(0)==len(a_list)//2:
                    print("Yes")
            else:
                    print("No")
        else:
                print("No")
else:
        if len(a)==3:
            a1=a[0]
            a2=a[1]
            a3=a[2]
            if a1 ^ a2 ==a3 and a1^a3==a2 and a2^a3==a1:
                if a_list.count(a1) == a_list.count(a2) == a_list.count(a3):
                        print("Yes")
                else:
                        print("No")
            else:
                print("No")
        else:
            print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a_i = list(map(int, input().split()))

a_i_set = list(set(a_i))

if len(a_i_set) == 3:
    if(a_i_set[0] ^ a_i_set[1] == a_i_set[2]) and (a_i.count(a_i_set[0]) == a_i.count(a_i_set[1]) == a_i.count(a_i_set[2])):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:

import numpy as np 

def make_bit(A):
    arr = np.zeros(31)
    i = 30
    while A:
        arr[i] = A % 2
        A = A // 2
        i -= 1

    return arr

def return_first_second_third(a_lst):
    first = [a_lst[0], 0]
    second = [-1, -1]
    third = [-1, -1]
    i = 0
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            second[0] = a_lst[i+1]
            second[1] = i+1
            i += 1
            break
        else:
            i += 1
    while i < len(a_lst) - 1:
        if a_lst[i] != a_lst[i+1]:
            third[0] = a_lst[i+1]
            third[1] = i+1
            i += 1
            break
        else:
            i += 1
    
    return first, second, third


N = int(input())

a_lst = list(map(int, input().split()))
a_lst.sort()
first, second, third = return_first_second_third(a_lst)
a_lst.reverse()

done = False
if second[0] == -1: # 全ての数が同じとき
    done = True
    if first[0] == 0: # 全ての数がゼロの時
        print("Yes")
    else:
        print("No")
elif third[0] == -1:    # 数が2種類だけの時
    done = True
    if N % 2 == 0 and second[1] == N // 2:
        print("Yes")
    else:
        print("No")
elif N % 3 == 0 and N != 3 and second[1] == N // 3 and third[1] == N * 2 // 3:
    a_lst = [ a_lst[0] + a_lst[second[1]] + a_lst[third[1]] ]


if not done:
    if N == 3:

        a1 = make_bit(a_lst[0])
        a2 = make_bit(a_lst[1])
        a3 = make_bit(a_lst[2])
        bits_arr = np.array([a1, a2, a3])

        judge = True
        for i in range(31):
            if bits_arr[0][i] == bits_arr[1][i] and bits_arr[2][i] == 1:
                judge = False
                break

            elif bits_arr[0][i] != bits_arr[1][i] and bits_arr[2][i] == 0:
                judge = False
                break
                
        if judge:
            print("Yes")
        else:
            print("No")


    else:
        print("No")

Submission status: Wrong Answer

Solution code:
# coding: utf-8

n = int(input())

camels = list(map(int, input().split()))

for i in range(n):
    left = i - 1
    right = i + 1 if i < n - 1 else 0
    if camels[left] ^ camels[right] != camels[i]:
        print('No')
else:
    print('Yes')

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
A = [int(_) for _ in input().split()]
count = collections.defaultdict(int)
for x in A:
    count[x] += 1
if len(count) == 1:
    a = list(count.keys())[0]
    if a == 0:
        print('Yes')
    exit()
elif len(count) == 2:
    a, b = sorted(count.keys())
    if a == 0 and count[b] == count[a] * 2:
        print('Yes')
        exit()
elif len(count) == 3:
    a, b, c = count.keys()
    if a ^ b == c and count[a] == count[b] == count[c]:
        print('Yes')
        exit()
print('No')

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if  a[i-1] ^ a[i] in a_ :
            a_.discard(a[i-1] ^ a[i])
        else:
            count += 1

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys

n = int(input())
a = list(map(int, input().split()))
b = [0]*n
flag = 0

for tsumugi in range(n - 1):
    for matsuri in range(tsumugi, n):
        if (a[0] ^ a[tsumugi] ^ a[matsuri] == 0):
            b[0] = a[0]
            b[1] = a[tsumugi]
            b[2] = a[matsuri]
            a[0] = 0
            a[tsumugi] = 0
            a[matsuri] = 0
            flag = 1
            break
    if (flag == 1):
        break

if (flag == 0):
    print("No")
    sys.exit()

if (n < 4):
    print("Yes")
    sys.exit()

#when n > 3
count_b = 0
flag1 = 0

for tomoka in range(n - 3):
    flag1 = 0
    for nao in range(n):
        if (a[nao] == 0):
            continue
        if (b[count_b] ^ b[count_b + 1] ^ a[nao] == 0):
            b[count_b + 2] = a[nao]
            a[nao] = 0
            count_b += 1
            flag1 = 1
            break
    if(flag1 == 0):
        print("No")
        sys.exit()
    
if (b[0] ^ b[n-1] ^ b[n] == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
from collections import Counter
def main():
    N = int( input())
    A = list( map( int, input().split()))
    CA = Counter(A)
    d = dict()
    if len(CA) > 3:
        print("No")
        return
    if len(CA) == 1:
        if CA[0] == N:
            print("Yes")
            return
        else:
            print("No")
            return
    if len(CA) == 2:
        for c in CA:
            if c != 0:
                t = c
        if N%3 == 0 and CA[t]== CA[0]*2:
            print("Yes")
        else:
            print("No")
        return
    ans = "Yes"
    for c in CA:
        if CA[c] != N//3:
            ans = "No"
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
*A, = map(int, input().split())
setA = set(A)
if len(setA) == 3:
    a, b, c = list(setA)
    if a ^ b ^ c == 0 and A.count(a) == A.count(b) == A.count(c): print('Yes')
    else: print('No')
elif len(setA) <= 2:
    maxA = max(setA)
    if 2*A.count(0) == A.count(maxA): print('Yes')
    else: print('No')
else: print('No')

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if(A.count(0) != 0):
    if(A.count(0) == N):
        print('Yes')
    elif(A.count(0) == N /3):
        a = -1
        b = -1
        aa = 0
        a = A.count(aa)

        bb = -1

        for i in A:
            if(aa != i):
                bb = i
                break
        if(bb != -1):
            b = A.count(bb)
            if(a + b == N):
                print('Yes')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')
else:
    if(N % 3 == 0):
        a = -1
        b = -1
        c = -1
        aa = A[0]
        a = A.count(aa)

        bb = -1

        for i in A:
            if(aa != i):
                bb = i
                break
        if(bb != -1):
            b = A.count(bb)
            if(a == b):
                cc = -1

                for i in A:
                    if(aa != i and bb != i):
                        cc = i
                        break
                if(cc != -1):
                    c = A.count(cc)
                    if(b == c and a + b + c == N):
                        print('Yes')
                    else:
                        print('No')
                else:
                    print('No')
            else:
                print('No')
        else:
            print('No')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n = input()
a = list(map(int, input().split()))

res = []
for n in range(len(a)):
  if(n == (len(a) - 1)):
    res.append(a[n - 1]^a[0])
  else:
    res.append(a[n - 1]^a[n + 1])

mes = "Yes"
for i, j in enumerate(res):
  if(a[i] != j):
    mes = ("No")
print(mes)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))

hats = A[:]
d = {}
for h in hats:
    d[h] = True

h1 = hats[0]
 
def search(now1, now2, count):
    now1, now2 = now2, now1^now2
    if now2 in d:
        if now2 == h1:
            if count == N:
                return True
            else:
                return False
        else:
            return search(now1, now2, count+1)
    else:
        return False
    

ans = False
for h2 in hats[1:]:
    if search(h1, h2, 2):
        ans = True

if ans:
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int, input().split())))
frag=False
if (a[1]==a[2]) and a[0] == 0: frag=True
if (a[2]-a[1])==(a[1]-a[0])==1: frag=True
if n > 3: frag=False
if (a[2]-a[1]==n):
    if a[1]%n != 0:
        frag=True
    else:
        if (a[1]//n)%2==0:
            frag=True
if sum(a)==0: frag=True
print("Yes" if frag else "No")

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if  a[i-1] ^ a[i] in a_ :
            count += 1
        else:
            a_.discard(a[i-1] ^ a[i])

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
nums = list(map(int, input().split()))

start = nums[0]

result = 'No'

for num in nums:
    if start ^ num not in nums:
        continue
    lists = [e for e in nums if e != start and e != num and e != start^num]

    if len(lists) == 0 and start ^ num == start^num:
        result = 'Yes'
        break

print(result)

Submission status: Wrong Answer

Solution code:
from collections import Counter

def solve(a):
    counter = Counter(a)
    l = list(counter.values())
    if counter[0] > 0:
        if len(l) != 2:
            return False
        return min(l) == counter[0] and counter[0] * 2 == max(l)
    ks = list(counter.keys())
    if len(l) != 3:
        return False
    return l[0] == l[1] and l[2] == l[0] and ks[0] ^ ks[1] == ks[2]



if __name__ == '__main__':
    n = int(input())
    a = [int(s) for s in input().split()]
    print('Yes' if solve(a) else 'No')

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a_2=[]
for i in range(len(a)):
    a_2.append(bin(a[i]))
import collections
c = collections.Counter(a_2)
b=[]
out=0
for i in c.values():
    b.append(i)
if a.count(0)==0:#0がない場合
    if len(b)!=3:
        out=1
    elif b[0]!=b[1] or b[1]!=b[2]:
        out=1
else:#0あり
    if len(b)>2:
        out=1
    elif len(b)==1:
        pass
    elif len(b)==2:
        if a.count(0)*3==len(a):
            pass
        else:
            out=1
if out==0:
    print('Yes')
elif out==1:
    print('No')

Submission status: Wrong Answer

Solution code:
import sys
#input = sys.stdin.readline
from collections import Counter
def inpl(): return list(map(int, input().split()))

N = int(input())
A = inpl()
C = Counter(A)
K = list(C.keys())

if len(K) != 3 or not (C[K[0]] == C[K[1]] ==C[K[2]]):
    print("No")
else:
    if K[0] ^ K[1] == K[2]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

def main():
    num = int(input())
    data = list(map(int, input().split()))


    if num % 3 != 0:
        print('No')
    else:
        if num == 3:
            if data[0] ^ data[1] == data[2] and data[0] ^ data[2] == data[1] and data[1] ^ data[2] == data[0]:
                print('Yes')
            else:
                print('No')
        else:
            num_c = Counter(data)
            for ele in num_c.keys():
                if num_c[ele] % 2 != 0:
                    print('No')
                    break
            else:
                print('Yes')







if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())
a = list(map(int,input().split()))
a = collections.Counter(a)

value, count = list(a.keys()), list(a.values())

if len(value)<3:
    if len(value)==1:
        if sum(a)==0:
            print('Yes')
        else:
            print('No')

    if len(value)==2:
        if 0 in value:
            if count[0]==N/3 or count[1]==N/3:
                print('Yes')
            else:
                print('No')

        else:
            print('No')

if len(value)>=3:
    if count[0]+count[1]+count[2] == N:
        if value[0]^value[1]^value[2] == 0:
            if count[0]==count[1]==count[2]:
                print('Yes')
            else:
                print('No')

    else:
        print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
figure = list(map(int, input().split()))
figure1 = []
n_loop = n
p=0
for j in range(1,n):
  figure1.append(figure[0]^figure[j])
for k in range(2,n-1):
  if figure1[0]==figure[k]:
    number1 = figure[1]
    number2 = figure[k]
    number3 = figure[0]
    figure.remove(figure[0])
    figure.remove(figure[0])
    figure.remove(figure[k-2])
    figure1 = []
    n_loop -=3
    p+=1
    break
if p == 1:
  while(p ==(n-2)):
    for j in range(1,n_loop-p+1):
      now = number1^number2
      if(now==figure[j]):
        number1 = number2
        number2 = figure[j]
        p+=1
        figure.remove(figure[j])
        break
if(p!=(n-2)):
  print("No")

Submission status: Wrong Answer

Solution code:
import copy
import sys

# 条件に合う帽子が複数ある場合を考慮する
def check_hats(hat_1, hat_2, hats):
    can_loop = True
    while can_loop:
        hat_3 = hat_1 ^ hat_2
        if hat_3 in hats: # 条件を満たすハットが見つかれば
            hats.remove(hat_3)
            hat_1 = hat_2
            hat_2 = hat_3
            
            if len(hats) <= 0:
                can_loop = False
        else:
            # まだハットが残ってるのに、これ以上進めない場合
            hats = None
            can_loop = False

    # 全部乗せた場合
    if hat_2 ^ rakuda_2 == rakuda_1:
        print('Yes')
        sys.exit()
    else:
        hats = None

n = int(input())
rakuda = [0]*n
hats = list(map(int, input().split()))

hats.sort()
# 最初の一頭へ、aiのハットをかぶせる
rakuda_1 = hats[0]
hats.pop(0)

# # 次のラクダへ、何かを乗せる
for hi in range(0, len(hats)):
    rakuda_2 = hats[hi]    
    new_hats = copy.copy(hats)
    new_hats.pop(hi)

    # まだ全部置いてない場合、条件を満たす数値があるかチェック
    hat_3 = rakuda_1 ^ rakuda_2
    if hat_3 in new_hats: # 条件を満たすハットが見つかれば
        new_hats.remove(hat_3)
        check_hats(rakuda_2, hat_3, new_hats)
    
# どの組み合わせもダメだった場合
print('No')
sys.exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int, input().split())))
frag=False
if (a[1]==a[2]) and a[0] == 0: frag=True
if (a[2]-a[1])==(a[1]-a[0])==1: frag=True
if n > 3: frag=False
if (a[2]-a[1]==n):
    if a[1]%n != 0:
        frag=True
    else:
        if (a[1]//n)%2==0:
            frag=True
print("Yes" if frag else "No")

Submission status: Wrong Answer

Solution code:
import collections

N = int(input())

a = list(map(int, input().split()))

a_coll  = collections.Counter(a)
a_key   = list(a_coll.keys())
a_value = list(a_coll.values())

if N % 3 != 0:
    if len(a_key) == 1 and a_key[0] == 0:
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(a_key) == 1:
    if a_key[0] == 0:
        print("Yes")
        exit()

if len(a_key) == 2:
    if 0 in a_key:
        print("Yes")
        exit()

for count in a_value:
    if count % (N / 3) != 0:
        print("No")
        exit()

if len(a_key) == 3:
    if a_key[0] ^ a_key[1] == a_key[2]:
        print("Yes")
        exit()

print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
arr.sort()
ans = 'Yes'
tmp0 = arr.count(0)
tmp1 = arr.count(1)
if tmp0 * 2 == tmp1 and tmp0 >0:
    print(ans)
    exit()

for i in range(N):
    if i == 0:
        if (arr[N-1] ^ arr[1]) == arr[0]:
            continue
        else:
            ans = 'No'
            break
    elif i == N-1:
        if (arr[N-2] ^ arr[0]) == arr[N-1]:
            continue
        else:
            ans = 'No'
            break
    else:
        if (arr[i-1] ^ arr[i+1]) == arr[i]:
            continue
        else:
            ans = 'No'
            break

print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    N = int(input())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    a_ = {int(x) for x in stdin.readline().rstrip().split()}
    count = 0


    for i in range(N):
        
        if not a[i-1] ^ a[i] in a_ and not a[i-1] in a_ and not a[i] in a_:

            count += 1
        a_.discard(a[i-1] ^ a[i])

    if count == 0:
        print("Yes")
    else:
        print("No")    


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import random
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def main():

	N = int(input())
	#S = list(input())
	#L,R = map(int, input().split(" "))
	#L = list(map(int, input().split(" ")))

	A = input().split()
	A = [int(s) for s in A]
	A.sort()

	a_max = A[-1]
	#A[-1] = -1

	a = 2
	i = 1
	ll = [1]
	while a < 100000+1:
		a = 2 ** i
		ll.append(a)
		i += 1
		if a_max == a:
			print("No")
			sys.exit()

	tmp = 0
	flg = False
	for i in ll:
		tmp += i
		if a_max == tmp:
			flg = True
			break
	
	#if flg == False:
			#print("No")
			#sys.exit()

	bk = -1
	next1 = -1
	for i, val in enumerate(A):
		#A[i] = -1
		if i == 0:
			tmp = a_max - val
			if tmp in A:
				bk = val
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
		if i == N-1:
			if next1 == a_max and bk ^ A[0] == a_max:
				print("Yes")
				sys.exit()
		
		if next1 == a_max:
			print("Yes")
			sys.exit()
			tmp = next1 - bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()

		elif next1 == A[0]:
			mylist = ["Yes", "No"]
			print(random.choice(mylist))
			sys.exit()
			tmp = a_max - next1
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				#print(next1)
				print("No")
				sys.exit()

		else:
			tmp = next1 + bk
			if tmp in A:
				bk = next1
				next1 = tmp
				continue
			else:
				print("No")
				sys.exit()
		
	print("No")


if __name__ == "__main__":
	main()