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 itertools

def solve(A):
    """
    >>> solve([1,2,3])
    Yes
    """
    if len(A) > 4:
        if all([i == 0 for i in A]):
            print("Yes")
        else:
            print("No")
    else:
        if (A[0] ^ A[1] ^ A[2]) == 0:
            print("Yes")
        else:
            print("No")


def main():
    N = int(input())
    A = list(map(int, input().split()))
    solve(A)


def _test():
    import doctest
    doctest.testmod()


if __name__ == "__main__":
    import sys
    argv = sys.argv
    if len(sys.argv) == 1:
        # no option
        main()
    elif sys.argv[1] == "-t":
        _test()
    else:
        input = open(sys.argv[1]).buffer.readline

Submission status: Wrong Answer

Solution code:

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()

a = list(set(LIST()))

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

Submission status: Wrong Answer

Solution code:

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()

a = set(LIST())

if N%3 == 0 and len(a) == 3:
	print("Yes")
elif len(a) == 1 and 0 in a:
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

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

def rule1(L):
    if len(set(L))!=2:
        return False
    if L.count(0)!=len(L)//3:
        return False
    return True

def rule2(L):
    if len(set(L))!=3:
        return False
    sL = set(L)
    if L.count(list(sL)[0])==L.count(list(sL)[1])==L.count(list(sL)[2]):
        return True
    else:
        return False

if sum(A)==0 or rule1(A) or rule2(A):
    print('Yes')
else:
    print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
x = [10**9+1,0]
y = [10**9+1,0]
z = [10**9+1,0]
for i in range(N):
    if x[0] == a[i]:
        x[1] += 1
    else:
        if x[1] == 0:
            x[0] = a[i]
            x[1] += 1
        elif y[0] == a[i]:
            y[1] += 1
        else:
            if y[1] == 0:
                y[0] = a[i]
                y[1] += 1
            elif z[0] == a[i]:
                z[1] += 1
            else:
                if z[1] == 0:
                    z[0] = a[i]
                    z[1] += 1

ans = 'No'
if x[0] == 0:
    if x[1] == N:
        ans = 'Yes'
    elif x[1]*2 == y[1] and x[1] + y[1] == N:
        ans = 'Yes'
if x[1] == y[1] == z[1] and x[1] + y[1] + z[1] == N:
    ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
a.sort()
x = [N + 1,0]
y = [N + 1,0]
z = [N + 1,0]
for i in range(N):
    if a[i] != x[0]:
        if x[1] == 0:
            x[0] = a[i]
            x[1] += 1
        elif a[i] != y[0]:
            if y[1] == 0:
                y[0] = a[i]
                y[1] += 1
            elif a[i] != z[0]:
                if z[1] == 0:
                    z[0] == a[i]
                    z[1] += 1
            else:
                z[1] += 1 
        else:
            y[1] += 1
    else:
        x[1] += 1
ans = 'No'
if x[0] == 0:
    if x[1] == N:
        ans = 'Yes'
    elif x[1]*2 == y[1] and x[1] + y[1] == N:
        ans = 'Yes'
if x[1] == y[1] == z[1] and x[1] + y[1] + z[1] == N:
    ans = 'Yes'

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
x = [0,0]
y = [0,0]
z = [0,0]
Count = [0 for _ in range(3)]
Zero = 0
for i in range(N):
    if a[i] ==0:
        Zero += 1
    elif a[i] != x[0]:
        if x[1] == 0:
            x[0] = a[i]
            x[1] += 1
        elif a[i] != y[0]:
            if y[1] == 0:
                y[0] = a[i]
                y[1] += 1
            elif a[i] != z[0]:
                if z[1] == 0:
                    z[0] == a[i]
                    z[1] += 1
                else:
                    ans = 'No'
            else:
                z[1] += 1 
        else:
            y[1] += 1
    else:
        x[1] += 1

if Zero == N or (x[1] + Zero == N and Zero != 0) or (x[1] == y[1] == z[1] and x[1] + y[1] + z[1] == N):
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
x = [0,0]
y = [0,0]
z = [0,0]
Count = [0 for _ in range(3)]
Zero = 0
for i in range(N):
    if a[i] ==0:
        Zero += 1
    elif a[i] != x[0]:
        if x[1] == 0:
            x[0] = a[i]
            x[1] += 1
        elif a[i] != y[0]:
            if y[1] == 0:
                y[0] = a[i]
                y[1] += 1
            elif a[i] != z[0]:
                if z[1] == 0:
                    z[0] == a[i]
                    z[1] += 1
            else:
                z[1] += 1 
        else:
            y[1] += 1
    else:
        x[1] += 1

if Zero == N or x[1] + Zero == N or (x[1] == y[1] == z[1] and x[1] + y[1] + z[1] == N):
    ans = 'Yes'
else:
    ans = 'No'
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if set(a) == {0}:
    print('Yes')
    exit()

flag = 0
if n % 3 == 0:
    if len(cnt) == 2:
        if cnt.get(0) == n // 3:flag = 1
    elif len(cnt) == 3:
        if len(set(cnt.values())) == 1:flag = 1

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if set(a) == {0}:
    print('Yes')
    exit()

flag = 0
if n % 3 == 0:
    if len(cnt) == 2:
        if cnt[0] == n // 3:flag = 1
    elif len(cnt) == 3:
        if len(cnt.values()) == 1:flag = 1

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

Submission status: Wrong Answer

Solution code:
from collections import Counter
from itertools import permutations
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if n % 3 != 0 or len(cnt) != 3:
    print('No')
else:
    key = []
    num = []
    for i, j in cnt.items():
        key.append(i)
        num.append(j)
    if len(set(num)) != 1:
        print('No')
    else:
        flag = 0
        for a, b, c in permutations(key):
            if a^b == c:
                flag = 1
                break
        if flag:print('Yes')
        else:print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = Counter(a)
if n % 3 != 0 or len(cnt) != 3:
    print('No')
else:
    key = []
    num = []
    for i, j in cnt.items():
        key.append(i)
        num.append(j)
    if len(set(num)) != 1:
        print('No')
    else:
        key.sort()
        if key[0]^key[2] == key[1]:
            print('Yes')
        else:
            print('No')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    l=[0]*N

    l[0]=A[0]
    i=0
    aset=set(A[1:])
    for a in aset:
        aset1=copy(aset)
        aset1.remove(a)
        l[1]=a
        f=1
        for j in range(0,N-2):
            na=l[j]^l[j+1]
            if na in aset1:
                aset1.remove(na)
                l[j+2]=na
            else:
                f=0
                break
        if f:
            if l[-1]^l[0]==l[1] and l[-2]^l[-1]==l[0]:
                print('Yes')
                return
    print('No')
    #print(l)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if A.count(0)==N:
    print("Yes")
elif N%3!=0:
    print("No")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    xor=0
    for a in set(A):
        if A.count(a)==N/3:
            xor^=a
        else:
            print("No")
            break
    if xor==0:
        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)==N:
    print("Yes")
elif N%3!=0:
    print("No")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    print("Yes" if all(A.count(a)==N/3 for a in set(A)) else "No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if A.count(0)==N:
    print("Yes")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    print("Yes" if all(A.count(a)==N/3 for a in set(A)) else "No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if A.count(0)==N:
    print("Yes")
elif len(set(A))==2:
    if 0 in set(A):
        if A.count(0)==N/3:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
elif len(set(A))==3:
    print("Yes" if all([A.count(a)==N/3] for a in set(A)) else "No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
def main():
    # 全部ゼロ
    if c[0] == n:
        ok = True
        return ok
    if n % 3 != 0:
        ok = False
        return ok
    # ゼロとその他1個でかつぜろが1/3個
    if c[0] == n // 3 and len(c) == 2:
        ok = True
        return ok
    # 全部違ってて1/3ずつでxorして0
    if len(c) != 3:
        ok = False
        return ok
    xor = 0
    for x in c:
        if c[x] != n // 3:
            ok = False
            return ok
        xor ^= x
    if ~xor:
        ok = True
    else:
        ok = False
    return ok
        
if __name__ == '__main__':
    print("Yes" if main() else "No")

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
c = Counter(map(int, input().split()))
def main():
    # 全部ゼロ
    if c[0] == n:
        ok = True
        return ok
    if n % 3 != 0:
        ok = False
        return ok
    # ゼロとその他1個でかつぜろが1/3個
    if c[0] == n // 3 and len(c) == 2:
        ok = True
        return ok
    # 全部違ってて1/3ずつでxorして0
    if len(c) > 3:
        ok = False
        return ok
    xor = 0
    for x in c:
        if c[x] != n // 3:
            ok = False
            return ok
        xor ^= x
    if ~xor:
        ok = True
    else:
        ok = False
    return ok
        
if __name__ == '__main__':
    print("Yes" if main() else "No")

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int,input().split()))
b = a[0]
c = a[-1]
a.insert(0,c)
a.append(b)

ans = "Yes"
for i in range(1,N+1):
  if a[i] != a[i-1] ^ a[i+1]:
    ans = "No"
    
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.append(A[0])
    A.append(A[1])
    A.append(A[2])
    ret = 'Yes'
    for i in range(1, N+2):
        if A[i-1]^A[i+1] != A[i]:
            ret = 'No'
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.append(A[0])
    A.append(A[1])
    ret = 'Yes'
    for i in range(1, N+1):
        if A[i-1]^A[i+1] != A[i]:
            ret = 'No'
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin python3
# -*- coding: utf-8 -*-

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.append(A[0])
    ret = 'Yes'
    for i in range(1, N):
        if A[i-1]^A[i+1] != A[i]:
            ret = 'No'
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 14 17:34:27 2020

@author: NEC-PCuser
"""

N = int(input())
a = list(map(int, input().split()))
a_len = len(a) + 1
ng_flg = False
while a_len >= 2:
    if a_len % 2 != 0:
        ng_flg = True
        break
    a_len = a_len // 2
        
if ng_flg is True:
    print("No")
else:
    a.sort()
    j = 0
    ans = "Yes"
    for i in range(len(a)):
        if i != j:
            ans = "No"
            break
        j += 1
    
    print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 14 17:34:27 2020

@author: NEC-PCuser
"""

N = int(input())
a = list(map(int, input().split()))
a.sort()
j = 0
ans = "Yes"
for i in range(len(a)):
    if i != j:
        ans = "No"
        break
    j += 1

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)

# 帽子の種類数を取得する
c_set = set(A)

# 帽子の種類数が1個の時、数値が0なら条件を満たす
if len(c_set) == 1:
    if c[0] == 0:
        print('Yes')
        exit()

# 帽子の種類数が2個の時、数値が0の帽子がN/3なら条件を満たす
elif len(c) == 2:
    if c[0] == N//3:
        print('Yes')
        exit()

# 帽子の種類数が3個の時、x^y^z=0で条件を満たす
elif len(c) == 3:
    check = -1
    check_list = []
    for a in c_set:
        check_list.append(a)
        if check == -1:
            check = c[a]
        else:
            if check != c[a]:
                print('No')
                exit(0)

    # 同じ個数ずつあった時に、x^y^z=0であるか
    if check_list[0] ^ check_list[1] ^ check_list[2] == 0:
        print('Yes')
        exit(0)
print('No')

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)

# 帽子の種類数を取得する
c_set = set(A)

# 帽子の種類数が1個の時、数値が0なら条件を満たす
if len(c_set) == 1:
    if c[0] == 1:
        print('Yes')
        exit()

# 帽子の種類数が2個の時、数値が0の帽子がN/3なら条件を満たす
elif len(c) == 2:
    if c[0] == N//3:
        print('Yes')
        exit()

# 帽子の種類数が3個の時、x^y^z=0で条件を満たす
elif len(c) == 3:
    check = -1
    check_list = []
    for a in c_set:
        check_list.append(a)
        if check == -1:
            check = c[a]
        else:
            if check != c[a]:
                print('No')
                exit(0)

    # 同じ個数ずつあった時に、x^y^z=0であるか
    if check_list[0] ^ check_list[1] ^ check_list[2] == 0:
        print('Yes')
        exit(0)
print('No')

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
 
if N%3 != 0:
  print('No')
  exit()
  
else:
  n = N//3
  ma = max(As)
  l = len(str(bin(ma))) - 2
  for i in range(l):
    c = 0
    for a in As:
      if (a>>i)%2 == 0:
        c += 1
    if c != n and c != N:
      print('No')
      exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int, input().split()))
 
if N%3 != 0:
  print('No')
  exit()
  
else:
  n = N//3
  ma = max(As)
  l = len(str(bin(ma))) - 2
  for i in range(l):
    c = 0
    for a in As:
      print(a>>i)
      if (a>>i)%2 == 0:
        c += 1
    if c != n and c != N:
      print('No')
      exit()

print('Yes')

Submission status: Wrong Answer

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

if sum(A) == 0:
    print('Yes')
    exit()

if len(A) % 3 != 0:
    print('No')
    exit()

c = Counter(A)
if len(c.values()) != 3:
    print('No')
    exit()

keys = list(c.keys())
for i, j, k in ([0, 1, 2], [1, 2, 0], [2, 1, 0]):
    if keys[i] ^ keys[j] != keys[k]:
        print('No')
        exit()

values = list(c.values())
if values[0] != values[1] or values[1] != values[2]:
    print('No')
    exit()

print('Yes')

# a b c a b c ...
# a xor b = c
# b xor c = a
# c xor a = b

# 全員0

Submission status: Wrong Answer

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

if N%3 != 0:
  print('No')
else:
  print('Yes')

Submission status: Wrong Answer

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

if N%3 != 0:
  print('No')
  exit()
  
else:
  n = N//3
  ma = max(As)
  l = len(str(bin(ma))) - 2
  for i in range(l):
    c = 0
    for a in As:
      if (a>>i)%2 == 0:
        c += 1
    if c != n:
      print('No')
      exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
def myAnswer(N:int,A:list) -> str:
   for n in range(N):
      if(n == 0):
         if(A[n+1] ^ A[-1] != A[n]):
            return "No"
      elif(n == N - 1):
         if(A[n-1] ^ A[0] != A[n]):
            return "No"
      elif(A[n - 1] ^ A[n + 1] != A[n]):
         return "No"
   return "Yes"

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

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

p=set(a[:n//3])
q=set(a[n//3:(n//3)*2])
r=set(a[(n//3)*2:n])

flag=True
if n%3!=0:
    flag=False
if n%2==0:
    s=set(a[:n//2])
    t=set(a[n//2:])
    if len(s)==1 and len(t)==1 and a[0]==0:
        print("Yes")
        sys.exit()
if len(set(a))==1:
    print("Yes")
    sys.exit()
    
if flag and len(p)==1 and len(q)==1 and len(r)==1:
    if a[0] ^ a[n//3]==a[(2*n)//3]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

p=set(a[:n//3])
q=set(a[n//3:(n//3)*2])
r=set(a[(n//3)*2:n])

flag=True
if n%3!=0:
    flag=False

if len(set(a))==1:
    print("Yes")
    sys.exit()
    
if flag and len(p)==1 and len(q)==1 and len(r)==1:
    if a[0] ^ a[n//3]==a[(2*n)//3]:
        print("Yes")
    elif a[0]==0 and a[n//3]==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

p=set(a[:n//3])
q=set(a[n//3:(n//3)*2])
r=set(a[(n//3)*2:n])

flag=True
if n%3!=0:
    flag=False

if len(set(a))==1:
    print("Yes")
    sys.exit()
    

if flag and len(p)==1 and len(q)==1 and len(r)==1:
    if a[0] & a[n//3]==a[(2*n)//3]:
        print("Yes")
    if a[0]==0 and a[n//3]==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

p=set(a[:n//3])
q=set(a[n//3:(n//3)*2])
r=set(a[(n//3)*2:n])

flag=True
if n%3!=0:
    flag=False


if flag and len(p)==1 and len(q)==1 and len(r)==1:
    if a[0] & a[n//3]==a[(2*n)//3]:
        print("Yes")
    if a[0]==0 and a[n//3]==0:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

S = S()
SUM = 0
MAX = 0
for s in S:
  if s == "T":
    SUM += 1
    MAX = max(MAX,SUM)
  else:
    SUM -= 1
print(MAX*2)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
n = int(input())
a = [int(i) for i in input().split()]
d = defaultdict(int)
for i in a:
    d[i] += 1
print("Yes"
if(
    (len(d) == 3 and len(set(d.values())) == 1 and n % 3 == 0)
    or (len(d) == 2 and n % 3 == 0 and d[0] == n // 3)
    or (sum(a) == 0)
)
else "No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
d = dict()
for i in a:
    d.setdefault(i, 0)
    d[i] += 1
print("Yes" if(len(d) == 3 and len(set(d.values())) == 1 and n % 3 == 0) or (len(d) == 2 and (sorted(d.values())[0] == n // 3) and n % 3 == 0) or (sum(a) == 0) else "No")

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    a = list(map(int, input().split()))

    c = Counter(a)
    ans = "No"
    if len(c) == 3:
        v = list(c.values())
        if v[0] == v[1] == v[2]:
            k = list(c.keys())
            if (k[0] ^ k[1] == k[2]) and (k[1] ^ k[2] == k[0]) and (k[2] ^ k[0] == k[1]):
                ans = "Yes"
    elif len(c) == 2:
        v = list(c.values())
        k = list(c.keys())
        v[0], v[1] = min(v), max(v)
        k[0], k[1] = min(k), max(k)
        if k[0] == 0 and v[0] * 2 == v[1]:
            ans = "Yes"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import Counter

input = sys.stdin.readline


def main():
    N = int(input())
    a = list(map(int, input().split()))

    c = Counter(a)
    ans = "No"
    if len(c) == 3:
        v = list(c.values())
        if v[0] == v[1] == v[2]:
            k = list(c.keys())
            if (k[0] ^ k[1] == k[2]) and (k[1] ^ k[2] == k[0]) and (k[2] ^ k[0] == k[1]):
                ans = "Yes"

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

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

for num in a:
    dd[num] += 1
    if len(dd) >= 4:
        print("No")
        exit()

if len(dd) == 1:    
    if dd[0] > 0:
        print("Yes")
    else:
        print("No")
    exit()

if n % 3 != 0:
    print("No")
    exit()
    
    
if len(dd) == 2:
    if dd[0] == n * 2 // 3:
        print("Yes")
    else:
        print("No")
        
else:
    lst = []
    for i, j in dd.items():
        lst.append(i)
        if j != n // 3:
            print("No")
            exit()
    if lst[0] ^ lst[1] ^ lst[2] == 0:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from functools import reduce
from collections import Counter


N = int(input())
a = list(map(int, input().split()))
if N % 3:
    print("No")
    exit()

nums = Counter(a)
ks = sorted(nums)
vs = sorted(nums.values())
if (
    (len(nums) == 1 and ks[0] == 0)
    or (len(nums) == 2 and ks[0] == 0 and vs[0] == N // 3)
    or (
        len(nums) == 3
        and all(v == N // 3 for v in vs)
        and reduce(lambda x, y: x ^ y, ks) == 0
    )
):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n+1):
    tmp = a[(i-1)%n] ^ a[(i+1)%n]
    if a[i%n] != tmp:
        print("No")
        exit()
print("Yes")

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

N = int(readline())
a = list(map(int,readline().split()))

if sum(a) == 0:
    print('Yes')
    exit()

if N%3 != 0:
    print('No')
    exit()

from collections import Counter

ac = Counter(a).most_common()

if len(ac) == 3 and ac[0][1] == ac[1][1] == ac[2][1] and ac[0][0] ^ ac[1][0] == ac[2][0]:
    print('Yes')
else:
    print('No')