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 math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n=int(input())
    a = list(map(int,input().split())) 
    if n%3!=0:
        print("No")
        exit()
    else:
        a.sort()
        x=a[0]
        z=a[n-1]
        if n%2==0:
            y=a[n//2]
        else:
            y=a[((n+1)//2)-1]
        x0=y0=z0=0
        for i in range(n):
            if a[i]==x:
                x0+=1
            if a[i]==y:
                y0+=1
            if a[i]==z:
                z0+=1
        if x==0 and x0==n//3 and y==z:
            print("Yes")
            exit()
        if x0!=n//3 or y0!=n//3 or z0!=n//3:
            print("No")
            exit()
        cnt={}
        index=0
        while x != 0:
            if x//2>0:
                if x%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                x=x//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                x=0
        index=0
        while y != 0:
            if y//2>0:
                if y%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                y=y//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                y=0
        index=0
        while z != 0:
            if z//2>0:
                if z%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                z=z//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                z=0
        for i in cnt:
            if cnt[i]%2==1:
                print("No")
                exit()
        print("Yes")

main()

Submission status: Wrong Answer

Solution code:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n=int(input())
    a = list(map(int,input().split())) 
    if n%3!=0:
        print("No")
        exit()
    else:
        a.sort()
        x=a[0]
        z=a[n-1]
        if n%2==0:
            y=a[n//2]
        else:
            y=a[((n+1)//2)-1]
        x0=y0=z0=0
        for i in range(n):
            if a[i]==x:
                x0+=1
            if a[i]==y:
                y0+=1
            if a[i]==z:
                z0+=1
        if x==0 and x0==n//3 and y==z:
            print("Yes")
            exit()
        if x0!=n//3 or y0!=n//3 or z0!=n//3:
            print("No")
            exit()
        cnt={}
        index=0
        while y != 0:
            if y//2>0:
                if y%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                y=y//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                y=0
        index=0
        while z != 0:
            if z//2>0:
                if z%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                z=z//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                z=0
        for i in cnt:
            if cnt[i]%2==1:
                print("No")
                exit()
        print("Yes")

main()

Submission status: Wrong Answer

Solution code:
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n=int(input())
    a = list(map(int,input().split())) 
    if n%3!=0:
        print("No")
        exit()
    else:
        a.sort()
        x=a[0]
        z=a[n-1]
        y=0
        if n%2==0:
            y=a[y//2]
        else:
            y=a[((y+1)//2)-1]
        x0=y0=z0=0
        for i in range(n):
            if a[i]==x:
                x0+=1
            if a[i]==y:
                y0+=1
            if a[i]==z:
                z0+=1
        if x0!=n//3 or y0!=n//3 or z0!=n//3:
            print("No")
            exit()
        cnt={}
        index=0
        while y != 0:
            if y//2>0:
                if y%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                y=y//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                y=0
        index=0
        while z != 0:
            if z//2>0:
                if z%2!=0:
                    if index not in cnt:
                        cnt[index]=1
                    else:
                        cnt[index]+=1
                z=z//2
                index+=1
            else:
                if index not in cnt:
                    cnt[index]=1
                else:
                    cnt[index]+=1
                z=0
        for i in cnt:
            if cnt[i]%2==1:
                print("No")
                exit()
        print("Yes")

main()

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ak = list(a.keys())
av = list(a.values())

if N % 3 != 0:
    if 0 in ak and len(ak) == 1:
        print('Yes')
    else:
        print('No')
elif len(ak) == 3:
    if ak[0] ^ ak[1] ^ ak[2] == 0:
        print('Yes')
    else:
        print('No')
elif len(ak) == 2:
    if 0 in ak:
        if a[0] == N // 3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
elif len(ak) == 1:
    if 0 in ak:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

ak = list(a.keys())
av = list(a.values())

if N % 3 != 0:
    if 0 in ak and len(ak) == 1:
        print('Yes')
    else:
        print('No')
elif len(ak) == 3:
    if ak[0] ^ ak[1] ^ ak[2] == 0:
        print('Yes')
    else:
        print('No')
elif len(ak) == 2:
    if 0 in ak:
        if a[0] == N // 3:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if 0 in ak:
        print('Yes')
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
N=int(input())
A=Counter(map(int,input().split()))

if len(A)==1:
  if 0 in A:
    print("Yes")
  else:
    print("No")
elif len(A)==2:
  if A[0]==N/3:
    print("Yes")
  else:
    print("No")
elif len(A)==3:
  if list(A.values())==[N/3]*3:
    print("Yes")
  else:
    print("No")
else:
  print("No")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections

N = int(input().split()[0])
a_list = list(map(int, input().split()))

counter = collections.Counter(a_list)

# 4種類以上だと、どうしようもない
is_ok = True
if len(counter) > 4:
    is_ok = False
elif len(counter) == 3:
    v_list = list(counter.values())
    if len(set(v_list)) != 1:
        # 全部同じ数ではない
        is_ok = False

    if is_ok:
        k_list = list(counter.keys())
        if k_list[0] ^ k_list[1] != k_list[2]:
            is_ok = False
else:
    for k in counter.keys():
        if k != 0:
            is_ok = False
            break

ans = "Yes" if is_ok else "No"

print(ans)

Submission status: Wrong Answer

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

a.sort()

if a[-1]==0:
    f=True
elif N%3!=0:
    f=False
elif a[0]==a[N//3-1] and a[N//3]==a[2*N//3-1] and a[2*N//3]==a[-1] and a[0]+a[N//3]==a[-1]:
    f=True
else:
    f=False

print('Yes' if f else 'No')

Submission status: Wrong Answer

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

def a():
    if n%3 > 0:
        if len(list(set(A))) == 1:
            return "Yes"
    else:
        B = list(set(A))
        if len(B) <= 3:
            c = 0
            t = 0
            for i in B:
                cou = A.count(i)
                if cou % (n//3) == 0:
                    c += 1
                    for i in range(cou // (n//3)):
                        t ^= i
            if c == len(B) and t == 0:
                return "Yes"
    return "No"

print(a())

Submission status: Wrong Answer

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

def a():
    if n%3 > 0:
        if len(list(set(A))) == 1:
            return "Yes"
    else:
        B = list(set(A))
        if len(B) <= 3:
            c = 0
            for i in B:
                if A.count(i) % (n//3) == 0:
                    c += 1
            if c == len(B):
                return "Yes"
    return "No"

print(a())

Submission status: Wrong Answer

Solution code:
from collections import Counter

n = int(input())
A = list(map(int,input().split()))

A = Counter(A)
V = Counter(A.values())

if len(A)==3 and len(V)==1:
    p,q,r = A.keys()
    if p^q^r == 0:
        print('Yes')
    else:
        print('No')
else:
    print('No')

Submission status: Wrong Answer

Solution code:

def binary_list(N):
    bin_list = []
    for i in range(36):
        bin_list.append(N % 2)
        N //= 2

    return bin_list

n = int(input())
a = input().split()

flag = True

binary_matrix = [[] for i in range(n)]

if n % 3 != 0:
    flag = False



for i in range(len(a)):
    a[i] = int(a[i])

if flag:
    for i in range(n):
        binary_matrix[i] = binary_list(a[i])

    for j in range(36):
        if flag:
            countof1 = 0
            for i in range(n):
               
                if binary_matrix[i][j] == 1:
                    countof1 +=1
            
            if countof1 != int(n*2/3) and countof1 != 0:
                flag = False
                break 
    
    c = True
    while c:
        countof1 = 0
        index3 = 0
        for j in range(36):
            index3 =0
            for i in range(n):
                if binary_matrix[i][j] == 0:
                    binary_matrix[i], binary_matrix[3*index3] = binary_matrix[3*index3] ,binary_matrix[i]
                    if 3*(index3 +1) < n:
                        index3 += 1
                        

                else:
                    c = False

        
    for j in range(36):
        for i in range(n):
            if binary_matrix[0][j] == 0:
                for index3 in range(int(n/3)):
                    if binary_matrix[3*index3][j] != 0:
                        flag = False
                        break
            elif binary_matrix[1][j] == 0:        
                for index3 in range(int(n/3)):
                    if binary_matrix[3*index3 + 1][j] != 0:
                        flag = False
                        break

            elif binary_matrix[2][j] == 0:        
                for index3 in range(int(n/3)):
                    if binary_matrix[3*index3 + 2][j] != 0:
                        flag = False
                        break

if flag:
    print("Yes")

else:
    print("No")

Submission status: Wrong Answer

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

import collections
At=collections.Counter(A)

Alist=At.most_common()

if len(Alist)!=3:
    print("No")
    exit()
elif not Alist[0][1]==Alist[1][1]==Alist[2][1]:
    print("No")
    exit()

Anum=[Alist[0][0],Alist[1][0],Alist[2][0]]
Anum.sort()

Astr=[""]*3
for i in range(3):
    temp=Anum[i]
    while temp>1:
        Astr[i]+=str(temp//2)
        temp%=2
    if temp==1:
        Astr[i]+="1"
    else:
        Astr[i]+="0"

SL=len(Astr[2])
for i in range(3):
    Astr[i]=Astr[i].zfill(SL)

temp=""
for i in range(SL):
    if Astr[0][i]==Astr[2][i]:
        temp+="0"
    else:
        temp+="1"
if temp!=Astr[1]:
    print("No")
    exit()

temp=""
for i in range(SL):
    if Astr[1][i]==Astr[0][i]:
        temp+="0"
    else:
        temp+="1"
if temp!=Astr[2]:
    print("No")
    exit()
temp=""
for i in range(SL):
    if Astr[1][i]==Astr[2][i]:
        temp+="0"
    else:
        temp+="1"
if temp!=Astr[0]:
    print("No")
    exit()
print("Yes")

Submission status: Wrong Answer

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

c = dict()

for x in a:
    if x not in c.keys():
        if len(c.keys()) >= 3:
            print('No')
            exit()
        else:
            c[x] = 1
    else:
        c[x] += 1

if len(c.keys()) == 1:
    if list(c.keys()) == 0:
        print('Yes')
    else:
        print('No')
elif len(c.keys()) == 2:
    p = [] + list(c.keys())
    p.sort()
    if p[0] != 0:
        print('No')
    elif c[p[0]] * 2 != c[p[1]]:
        print('No')
    else:
        print('Yes')
else:
    x, y, z = c.keys()
    if x ^ y != z:
        print('No')
    elif c[x] != c[y] or c[y] != c[z]:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

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

c = dict()

for x in a:
    if x not in c.keys():
        if len(c.keys()) >= 3:
            print('No')
            exit()
        else:
            c[x] = 1
    else:
        c[x] += 1

if len(c.keys()) == 1:
    if list(c.keys()) == 0:
        print('Yes')
    else:
        print('No')
elif len(c.keys()) == 2:
    p = [] + list(c.keys())
    p.sort()
    if p[0] != 0:
        print('No')
    elif c[p[0]] * 2 != c[p[1]]:
        print('No')
    else:
        print('Yes')
else:
    x, y, z = c.keys()
    if x ^ y ^ z != 0:
        print('No')
    elif c[x] != c[y] or c[y] != c[z]:
        print('No')
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    A_c = Counter(A)
    if set(A) == {0}: return print("Yes")
    if len(set(A)) > 3: return print("No")
    if len(set(A)) == 3:
        k = list(A_c.items())
        if k[0][0] ^ k[1][0] ^ k[2][0] == 0 and k[0][1] == 3//N and k[1][1] == N//3 and k[2][1] == N/3:
            return print("Yes")
        else:
            return print("No")
    if len(set(A)) == 2:
        k = list(A_c.items())
        if (k[0][0] == 0 and k[0][1] == N//3) or (k[1][0] == 0 and k[1][1] == N//3):
            return print("Yes")
    print("No")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    if set(A) == {0}: return print("Yes")
    if N > 3: return print("No")
    if A[0] ^ A[2] == A[1] and A[1] ^ A[2] == A[0] and A[0] ^ A[1] == A[2]:
        print("Yes")
    else:
        print("No")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    for i in range(N-2):
        if A[i] ^ A[i+2] != A[i+1]:
            print("No")
            break
    else:
        if A[N-2] ^ A[0] == A[N-1] and A[N-1] ^ A[1] == A[0]:
            print("Yes")
        else:
            print("No")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    A_c = [[i,j] for i,j in Counter(A).items()]
    A_s = {A_c[i][0] for i in range(len(A_c))}
    cnt = 1
    l = [A_c[0][0]]
    A_c[0][1] -= 1
    if A_c[0][1] == 0: A_s.discard(A_c[0][0])
    next = l[-1] ^ A_c[-1][0]
    i = 1
    while len(l) < N:
        if next in A_s:
            l.append(A_c[-i][0])
            A_c[-i][1] -= 1
            i = 1
        else:
            i += 1
            if len(A_c) < i:
                break
        next = l[-1] ^ A_c[-i][0]
    else:
        print("Yes")
    for i in range(N-2):
        if A[i] ^ A[i+1] != A[i+2]:
            print("No")
            break
    else:
        if A[N-2] ^ A[N-1] == A[0] and A[N-1] ^ A[0] == A[1]:
            return print("Yes")
        else:
            pass
            print("No")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    for i in range(N-2):
        if A[i] ^ A[i+1] != A[i+2]:
            #print("No")
            break
    else:
        if A[N-2] ^ A[N-1] == A[0] and A[N-1] ^ A[0] == A[1]:
            return print("Yes")
        else:
            pass
            #print("No")
    from collections import Counter
    A_c = [[i,j] for i,j in Counter(A).items()]
    A_s = {A_c[i][0] for i in range(len(A_c))}
    cnt = 1
    l = [A_c[0][0]]
    A_c[0][1] -= 1
    if A_c[0][1] == 0: A_s.discard(A_c[0][0])
    next = l[-1] ^ A_c[-1][0]
    i = 1
    while len(l) < N:
        if next in A_s:
            l.append(A_c[-i][0])
            A_c[-i][1] -= 1
            i = 1
        else:
            i += 1
            if len(A_c) < i:
                print("No")
                break
        next = l[-1] ^ A_c[-i][0]
    else:
        print("Yes")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    for i in range(N-2):
        if A[i] ^ A[i+1] != A[i+2]:
            print("No")
            break
    else:
        if A[N-2] ^ A[N-1] == A[0] and A[N-1] ^ A[0] == A[1]:
            print("Yes")
        else:
            print("No")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    A_c = [[i,j] for i,j in Counter(A).items()]
    A_s = {A_c[i][0] for i in range(len(A_c))}
    cnt = 1
    l = [A_c[0][0]]
    A_c[0][1] -= 1
    if A_c[0][1] == 0: A_s.discard(A_c[0][0])
    next = l[-1] ^ A_c[-1][0]
    i = 1
    while len(l) < N:
        if next in A_s:
            l.append(A_c[-i][0])
            A_c[-i][1] -= 1
            i = 1
        else:
            i += 1
            if len(A_c) < i:
                print("No")
                break
        next = l[-1] ^ A_c[-i][0]
    else:
        print("Yes")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=set()
cnt=[]
zero=0
for i in range(n):
	if a[i]==0:
		zero+=1
	elif a[i] not in p:
		p.add(a[i])
		cnt.append(1)
	else:
		p=list(p)
		for j in range(len(p)):
			if a[i]==p[j]:
				cnt[j]+=1
		p=set(p)
	if len(p)>=4:
		print("No")
		exit()
if n%3!=0 and zero!=n:
	print("No")
	exit()
if len(p)>=4:
	print("No")
	exit()
p=list(p)
if len(p)==3:
	if cnt[0]==cnt[1]==cnt[2]==n/3:
		if p[0]^p[1]^p[2]==0:
			print("Yes")
			exit()
	else:
		print("No")
		exit()
elif len(p)==1:
	if cnt[0]==n/3*2:
		print("Yes")
		exit()
elif len(p)==0:
	if sum(a)==0:
		print("Yes")
		exit()
print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=[]
cnt=[]
for i in range(n):
	if a[i]!=0 and a[i] not in p:
		p.append(a[i])
		cnt.append(1)
	elif a[i]!=0:
		for j in range(len(p)):
			if a[i]==p[j]:
				cnt[j]+=1
if len(p)>=4 or n%3!=0:
	print("No")
	exit()
if len(p)==3:
	if cnt[0]==cnt[1]==cnt[2]==n/3:
		if p[0]^p[1]^p[2]==0:
			print("Yes")
			exit()
elif len(p)==1:
	if cnt[0]==n/3*2:
		print("Yes")
		exit()
elif len(p)==0:
	if sum(a)==0:
		print("Yes")
		exit()
print("No")

Submission status: Wrong Answer

Solution code:
import collections
import itertools

n = int(input())
ls = list(map(int, input().split()))
counter = collections.Counter()
for x in ls:
    counter[x] += 1
if len(counter.keys()) > 3:
    print('No')
else:
    for a, b in itertools.combinations(counter.keys(), 2):
        if a == b and counter[a] == 1:
            continue
        counter2 = collections.Counter()
        x = a
        counter2[a] += 1
        counter2[b] += 1
        for _ in range(n - 2):
            a, b = b, a ^ b
            counter2[b] += 1
            if counter2[b] > counter[b]:
                break
        else:
            if a ^ b != x:
                continue
            else:
                print('Yes')
                break
    else:
        print('No')

Submission status: Wrong Answer

Solution code:
import collections
import itertools

n = int(input())
ls = list(map(int, input().split()))
counter = collections.Counter()
for x in ls:
    counter[x] += 1
if len(counter.keys()) > 3:
    print('No')
else:
    for a, b, c in itertools.combinations(counter.keys(), 3):
        if not (a ^ b == c and a ^ c == b and b ^ c == a):
            print('No')
            break
    else:
        print('Yes')

Submission status: Wrong Answer

Solution code:

def logicalsum_str(a, b):
    La = len(a)
    Lb = len(b)
    ans = ""
    if La >= Lb:
        for i in range(Lb):
            if a[-(1 + i)] == b[-(1 + i)]:
                ans = "0" + ans
            else:
                ans = "1" + ans
        ans = a[0:La-Lb] + ans
    else:
        for i in range(La):
            if a[-(1 + i)] == b[-(1 + i)]:
                ans = "0" + ans
            else:
                ans = "1" + ans
        ans = a[0:Lb-La] + ans

    return ans

N=int(input())
A=list(map(int,input().split()))
B=[""]*N
for i in range(N):
    temp=A[i]
    if temp==0:
        B[i]="0"
    while temp>0:
        B[i]=str(temp%2)+B[i]
        temp=temp//2

if int(B[0])!=int(logicalsum_str(B[-1],B[1])) or  int(B[-1])!=int(logicalsum_str(B[-2],B[0])):
    print("No")
    exit()

for i in range(2,N-1):
    if int(B[i])!=int(logicalsum_str(B[i-1],B[i+1])):
        print("No")
        exit()

print("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
a.sort()
for i in range(N-1):
    if a[i+1] - a[i] != 1:
        print("No")
        break
else:
    print("Yes")

Submission status: Wrong Answer

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

if N%2==0:
  print("No")
else:
  b=0
  for a in A:
    b^=a
  #print(b)
  print("No" if b else "Yes")

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

mc = Counter(a).most_common()
ln = len(mc)

def detect():
    if ln == 1 and mc[0][0] == 0:
        return True
    elif ln == 2 and mc[1][0] == 0 and mc[1][1] == n // 3:
        return True
    elif ln == 3 and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0:
        return True

print("Yes" if detect() else "No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
n = int(input())
a = [int(i) for i in input().split()]
if sum(a):
    if n%3: f = 0
    else:
        d,x = dd(int),[]
        for i in a: d[i]+=1
        for i in d.keys(): x.append(i)
        if len(d)==2 and d[0]==n//3: f = 1
        elif len(d)==3 and x[0]^x[1]^x[2] and d[x[0]]==d[x[1]]==d[x[2]]: f = 1
        else: f = 0
else: f = 1
if f: print("Yes")
else: print("No")

Submission status: Wrong Answer

Solution code:
from collections import defaultdict as dd
n = int(input())
a = [int(i) for i in input().split()]
if n%3 and sum(a): print("No")
elif n%3: print("Yes")
else:
    d,x = dd(int),[]
    for i in a: d[i]+=1
    if len(d)==2 and d[0]==n//3: print("Yes")
    elif len(d)==2: print("No")
    elif len(d)!=3: print("No")
    else:
        for i in d.keys(): x.append(i)
        if x[0]^x[1]==x[2]: print("Yes")
        else: print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
def solve(A):
  if len(A) % 3 != 0: return False
  count = {}
  for x in A:
    if x not in count:
      count[x] = 0
    count[x] += 1
    
  xs = []
  for k, v in count.items():
    if v % (N//3) != 0: return False
    for _ in range(v // (N//3)):
      xs.append(k)
  return (xs[0] == xs[1] ^ xs[2]) or (xs[1] == xs[2] ^ xs[0]) or (xs[2] == xs[0] ^ xs[1])

print('Yes' if solve(A) else 'No')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = len(a)
a.append(a[0])
a.append(a[1])
c = 0
if max(a) == 0:
  print('Yes')
else:
  for i in range(b-1):
    if a[i]^a[i+1]^a[i+2] == 0 and a[i+1]^a[i+2]^a[i+3] == 0:
      c += 1
  if c != 0:
    print('Yes')
  else:
    print('No')

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1

key = list(d.keys())
if len(d) == 1 and key[0] == 0:
    ans = "Yes"
elif len(a) % 3 != 0:
    ans = "No"
else:
    if len(d) == 2:
        if d[key[0]] == d[key[1]]*2 and key[0] == 0:
            ans = "Yes"
        elif d[key[1]] == d[key[0]]*2 and key[1] == 0:
            ans = "Yes"
        else:
            ans = "No"
    elif len(d) == 3:
        if d[key[0]] == d[key[1]] and d[key[1]] == d[key[2]] and key[0] ^ key[1] ^ key[2] == 0:
            ans = "Yes"
        else:
            ans = "No"
    else:
        ans = "No"

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for i in range(n):
    d[a[i]] += 1


if len(d) == 1 and 0 in d:
    ans = "Yes"
elif len(a) % 3 != 0:
    ans = "No"
else:
    key = list(d.keys())
    if len(d) == 2:
        if d[key[0]] == d[key[1]]*2 and key[0] ^ key[1] ^ key[1] == 0:
            ans = "Yes"
        elif d[key[1]] == d[key[0]]*2 and key[1] ^ key[0] ^ key[0] == 0:
            ans = "Yes"
        else:
            ans = "No"
    elif len(d) == 3:
        if d[key[0]] == d[key[1]] and d[key[1]] == d[key[2]] and key[0] ^ key[1] ^ key[2] == 0:
            ans = "Yes"
        else:
            ans = "No"
    else:
        ans = "No"

print(ans)