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:
def sol(N, _as):
    if N % 3 != 0:
        return False

    first = _as.pop()
    for second in _as:
        success = True
        __as = _as[:]
        __as.remove(second)
        latest = second
        pre_latest = first
        while len(__as) > 0:
            _latest = latest
            latest = pre_latest^latest
            pre_latest = _latest
            try:
                __as.remove(latest)
            except ValueError:
                success = False
                break
        if success and pre_latest^latest == first:
            return True
    return False


def solve(N, _as):
    if N % 3 != 0:
        return False

    max_bit_len = 0
    max_bit_len_ints = []
    other_ints = []
    for a in _as:
        bl = int.bit_length(a)
        if bl > max_bit_len:
            max_bit_len = bl
            other_ints.extend(max_bit_len_ints)
            max_bit_len_ints.clear()
            max_bit_len_ints.append(a)
        elif bl == max_bit_len:
            max_bit_len_ints.append(a)
        else:
            other_ints.append(a)

    if N / 3 != len(other_ints):
        return False

    first = max_bit_len_ints.pop()
    for second in other_ints:
        return _solve(first, second, max_bit_len_ints, other_ints)


def _solve(first, second, _max_bit_len_ints, _other_ints):
    max_bit_len_ints = _max_bit_len_ints[:]
    other_ints = _other_ints[:]
    other_ints.remove(second)

    pre_latest = second
    latest = first^second
    try:
        max_bit_len_ints.remove(latest)
    except ValueError:
        return False

    count = 0
    while len(max_bit_len_ints) > 0 and len(other_ints) > 0:
        _latest = latest
        latest = pre_latest^latest
        pre_latest = _latest
        if count == 0 or count == 2:
            try:
                max_bit_len_ints.remove(latest)
            except ValueError:
                return False
        else:
            try:
                other_ints.remove(latest)
            except ValueError:
                return False
        count = (count + 1) % 3

    return pre_latest^latest == first


if __name__ == '__main__':
    N = int(input())
    _as = [int(x) for x in input().split()]
    print('Yes' if sol(N, _as) else 'No')

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int, input().split()))
b=sorted(a)
result = True
for idx in range(len(b)-1):
    prev = b[idx-1]
    next = b[idx+1]
    diff = next - prev
    if idx == 0:
        diff = -diff
    if diff == b[idx]:
        result_tmp = True
    else:
        result_tmp = False
        result = False
        break
diff = abs(b[0] + b[len(b)-2])
if diff != b[len(b)-1]:
    result = False
str = "Yes" if result == True else "No"
print(str)

Submission status: Wrong Answer

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

a_unique = list(set(a))

if len(a_unique) > 3:
    result = False

elif len(a_unique) == 3:
    if a_unique[0]^a_unique[1] == a_unique[2]:
        pass
    else:
        result = False

elif len(a_unique) == 1:
    if a_unique[0]^a_unique[0] == a_unique[0]:
        pass
    else:
        result = False

elif len(a_unique) == 2:
    if a_unique.count(a_unique[0]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[1]:
            if a_unique[1]^a_unique[1] == a_unique[0]:
                pass
            else:
                result = False
    elif  a_unique.count(a_unique[1]) == 1:
        if a_unique[0]^a_unique[1] == a_unique[0]:
            if a_unique[0]^a_unique[0] == a_unique[1]:
                pass
            else:
                result = False
                
if result:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import collections

N = input()
N = int(N)
a = [ int(i) for i in input().split()]
c = collections.Counter(a)
hoge = False

def check(i,j):
    c[j] -= 1
    for k in range(len(a)-1):
        if c[i^j] == 0:
            return True
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return True

for  i in range(len(a)-1):
    for j in range(i+1,len(a)):
        if check(a[i],a[j]):
            hoge = True
            break
        else:
            break
    else:
        continue
    break

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

Submission status: Wrong Answer

Solution code:
n=input()
n=int(n)
a=list(map(int,input().split()))
ans="Yes"
if n%3!=0:
  ans="No"
c=0
i=1
while 2**i<max(a):
  c=0
  for j in range(n):
    
    if (a[j]//(2**(i-1)))%(2**i)==1:
      c+=1
  if c!=n/3*2:
    ans="No"
    break
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
a = int(input())
b = list(map(int, input().split()))
c = {}
for i in range(a):
    if b[i] not in c:
        c.setdefault(b[i], 1)
    else:
        c[b[i]] += 1
if len(c) != 3:
    print("No")
    exit()
else:
    f = list(c.values())
    for i in range(1, len(c)):
        if f[i] != f[i-1]:
            print("No")
            exit()
    if f[0] ^ f[1] == f[2]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
a = list(int(i) for i in input().split())
chk = sum(a)
if a == [0] *N:
	print("Yes")
else:
	if N == 3:
			if (a[0]^a[1]) == a[2]:
				print("Yes")
			else:
				print("No")
	else:
		l = collections.Counter(a)
		if a.count(0) == 0:
			if list(l.values()) ==  [list(l.values())[0]] * len(l.values()) and len(l.keys()) == 3:
				if ((list(l.keys())[0])^(list(l.keys())[1])) == list(l.keys())[2]:
					print("Yes")
				else:
					print(list(l.keys())[0])
					print("No")
			else:
				print("No")
		else:
			if len(l.values()) == 2 and a.count(0) == N//3:
				print("Yes")
			else:
				print("No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if(N % 3 != 0):
    print('No')
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
b = A.count(bb)
if(a == b):
    cc = -1

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]

if 0 in a:
    print("Yes")

else:
    if n%3 != 0:
        print("No")

    else:
        if len(set(a)) != 3 or a.count(list(set(a))[0]) != int(n/3) or a.count(list(set(a))[1]) != int(n/3) or a.count(list(set(a))[2]) != int(n/3):
            print("No")

        else:
            set_a = list(set(a))
            if set_a[0] == set_a[1]^set_a[2] and set_a[1] == set_a[2]^set_a[0] and set_a[2] == set_a[1]^set_a[0]:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

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

def xor(a0, a1, a: list):
    is_xor_exist = False
    a2 = 0
    #print(a0,a1,a)
    if len(a) == 0:
        return a0,a1,a,is_xor_exist
    else:
        for ai in a:
            if a0 ^ ai == a1:
                a.remove(ai)
                a2 = ai
                is_xor_exist = True
                break

        return a1, a2, a, is_xor_exist

result = "No"

a0 = a[0]
a.remove(a0)

for ai in a:
    a1 = ai
    a_mlist = a
    a_mlist.remove(a1)
    a1, a2, a_mlist, is_xor_exist = xor(a0, a1, a_mlist)
    if is_xor_exist:
        while is_xor_exist:
            a1, a2, a_mlist, is_xor_exist = xor(a1, a2, a_mlist)
        if len(a_mlist) == 0:
            if a1 ^ a0 == a2:
                result = "Yes"
                break
                
print(result)

Submission status: Wrong Answer

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

ans = 0
if n == 3:
    if a[0]^a[1] == a[2]:
        ans = 1
    else:
        ans = 0
elif n == 4:
    if a[0]==0 and a[1]==0 and a[2]==0 and a[3]==0:
        ans = 1
    else:
        ans = 0
else:
    tmp = []
    cnt = []
    for x in a:
        if x not in tmp:
            tmp.append(x)
            cnt.append(1)
        else:
            cnt[-1] += 1
    if n % 3 != 0:
        if tmp[0] == 0 and cnt[0] == n:
            ans = 1
    else:
        if len(tmp) == 3:
            if max(cnt) == min(cnt):
                ans = 1
        if len(tmp) == 2:
            if 0 in tmp:
                i = tmp.index(0)
                if cnt[i]*2 == cnt[i+1]:
                    ans = 1
        if len(tmp) == 1:
            if tmp[0] == 0:
                ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = input().split(' ')

an = np.array(A, dtype=np.int64)

for i in range(1,N):
   for j in range(i+1,N):
      if(an[0] == an[i]^an[j]):
         tmp = an[1]
         an[1] = an[i]
         an[i] = tmp

         tmp = an[2]
         an[2] = an[j]
         an[j] = tmp

         doo = 1
         break
      else:
         doo = 0

if(doo == 0):
   print('No')

for i in range(2,N):
   for j in range(i+1,N):
      if(an[i-1] == an[i]^an[j]):
         tmp = an[i+1]
         an[i+1] = an[j]
         an[j] = tmp
         doo=1
         break
      else:
         doo=0

   if(doo==0):
      print('No')
      break

if(doo==1):
   print('Yes')

Submission status: Wrong Answer

Solution code:
import itertools
import sys
import copy

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

def q(line):
  flg = True
  for i in range(len(line)):
    max = i + 1
    min = i - 1
    if i + 1 > n - 1:
      max = 0
    elif i - 1 < 0:
      min = n - 1
    wa = line[min] ^ line[max]
    if line[i] != wa:
      flg = False
  return flg

# 1回やる
flg = q(line)
if flg:
  print('Yes')
  sys.exit()

# 数字
for i in line:
  line2 = copy.copy(line)
  line2.remove(i)
  flg = True
  for v in itertools.permutations(line2,2):
    if i == list(v)[0] ^ list(v)[1]:
      flg = False
      break
  if flg:
    print('No')
    sys.exit()

print('Yes')

Submission status: Wrong Answer

Solution code:
N = int(input())
Rakuda_data =  input().split(' ')
flag = 0

for n in range(0, N):
    if 0 < int(n) and int(n) < N-1:
        Flontstr = int(Rakuda_data[n-2])
        binstr = int(Rakuda_data[n-1])
        Afterstr = int(Rakuda_data[n])
        # XOR回路
        if bin(Flontstr ^ Afterstr) != bin(binstr):
            flag=1

if flag==1:
    print('No')
elif flag==0:
    print('Yes')

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python

import sys

n= int(sys.stdin.readline())
ai  = []
even= []
odd = []
lmax= 0
for i,x in enumerate( sys.stdin.readline().split() ):
    a = int(x)
    ai.append(a)
    #
    if a%2==0: even.append(i)
    else: odd.append(i)
    #
    tmp= len(bin(a))-2
    if tmp>lmax: lmax= tmp
#
ne= len(even)
no= len(odd)
if no!=0 and no!=2*ne:
    print( "No" )
    exit()
#
first=[]
for e in even:
    ee = ai[e]
    if len(bin(ee))==lmax+2: first.append(ee)
#
if len(first)==0:
    print( "No" )
    exit()
#
second=[]
if no>0:
    for o in odd:
        oo = ai[o]
        if len(bin(oo))==lmax+2: second.append(oo)
else:
    for e in even:
        ee = ai[e]
        if len(bin(ee))==lmax+2: second.append(ee)
#
if len(second)==0:
    print( "No" )
    exit()
#
tc= []
for f in first:
    for s in second:
        if f==s: continue
        tc.append( (f,s) )
#
ans= "No"
for f,s in tc:
    tmp= [f,s]
    for i in range(2,n):
        nn = f ^ s
        if nn in ai and not nn in tmp:
            tmp.append(nn)
        else:
            break
    #
    if len(tmp)==n:
        ans="Yes"
        break
#
print( ans )

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/agc035/tasks/agc035_a
import numpy as np


def calc(N: int, values: np.ndarray) -> bool:
    return any([calc3(N, values), calc_0_1(N, values)])


def calc3(N: int, values: np.ndarray) -> bool:
    if N % 3 != 0:
        return False

    uniques = np.unique(values)
    if len(uniques) != 3:
        return False

    counts = [np.sum(values == v) for v in uniques]  # 各固有値の格納数
    if len(np.unique(counts)) != 1:
        return False

    sorted_uniques = np.sort(uniques)
    return all(
        [
            sorted_uniques[0] == np.bitwise_xor(sorted_uniques[1], sorted_uniques[2]),
            sorted_uniques[1] == np.bitwise_xor(sorted_uniques[2], sorted_uniques[0]),
            sorted_uniques[2] == np.bitwise_xor(sorted_uniques[0], sorted_uniques[1]),
        ]
    )


def calc_0_1(N: int, values: np.ndarray) -> bool:
    """
    0000...0 or 1111...1 only pattern
    """
    if N < 4:
        return False
    if N % 2 != 0:
        return False

    max_value = np.max(values)
    # max value must be 1111...1
    if not number_is_all_bit_1(max_value):
        return False

    uniques = np.unique(values)
    if set(uniques) != {0, max_value}:
        return False

    counts = [np.sum(values == v) for v in uniques]  # 各固有値の格納数
    if len(np.unique(counts)) != 1:
        return False

    return True


def number_is_all_bit_1(value: int) -> bool:
    if value == 0:
        return False
    if value == 1:
        return True
    ex = 1
    compare = 2
    while compare - 1 <= value:
        if value == compare - 1:
            return True
        ex += 1
        compare = 2 ** ex

    return False


def load_input_as_int_array():
    return np.array([int(v) for v in input().split(" ")])


N = int(input())
values = load_input_as_int_array()
result = calc(N, values)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
figure = list(map(int, input().split()))
p=0
for i in range(n-2):
  for j in range(i+1,n-1):
    now = figure[i]^figure[j]
    for k in range(j+1,n):
      if now==figure[k]:
        print("Yes")
        p+=1
        break
    else: 
      continue
    break
  else:
    continue
  break
if p==0:
  print("No")

Submission status: Wrong Answer

Solution code:
import math

N = int(input())

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

def xor(x1,x2):
    xdigit = math.ceil(math.log2(max(x1+1, x2+1)))
    num = 0
    
    #print(x1, x2)
    
    for i in range(xdigit):
        dig_x1 = x1 // (2**(xdigit-i-1))
        dig_x2 = x2 // (2**(xdigit-i-1))
        
        #print("x", dig_x1, dig_x2)
        
        if dig_x1 != dig_x2:
            num += 2**(xdigit-i-1)
            
        if dig_x1 == 1:
            x1 -= 2**(xdigit-i-1)
            
        if dig_x2 == 1:
            x2 -= 2**(xdigit-i-1)
    return num

is_exist = True

for camel in range(N):
    if camel == N-1:
        furt = 0
    else:
        furt = camel + 1
        
    if camel == 0:
        prev = N-1
    else:
        prev = camel -1
         
    num_xor = xor(nums[prev], nums[furt])
    
    #print(num_xor)
    
    #print(camel, num_xor, nums[camel])
    
    if num_xor != nums[camel]:
        is_exist = False
        break


if is_exist == True:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

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

from collections import defaultdict
cnt_dict = defaultdict(int)
for a in A:
    cnt_dict[a] += 1

# 全部の排他的論理和を取る
res = A[0]
for a in A[1:]:
    res ^= a

if N%3 != 0:
    start = A[0]
    cnt_dict[start] -= 1
    for i in range(1,N):
        cnt_dict[res^A[i]] -= 1
        if cnt_dict[res^A[i]] < 0:
            print("No")
            quit()
        start = res^A[i]
    else:
        print("Yes")
else:
    lists = []
    for i in range(3):
        for a in A:
            if cnt_dict[a] >0:
                start = a
                break
        cnt_dict[start] -= 1
        seq = [start]
        
        for i in range(1,N//3):
            cnt_dict[res^A[i]] -= 1
            if cnt_dict[res^A[i]] < 0:
                print("No")
                quit()
            start = res^A[i]
            seq.append(start)
        lists += [seq]
    
    # 一通りでも存在するかどうかを確かめる
    for i in lists[1]:
        if lists[0][0]^i in lists[2]:
            print("Yes")
            quit()
    else:
        print("No")

Submission status: Wrong Answer

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

    for i in range(N - 1):
        if A[i - 1] ^ A[i + 1] != A[i]:
            print("No")
            return

    if A[-2] ^ A[0] != A[-1]:
        print("No")
        return

    print("Yes")
    return


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = input()
dic = {}
for i in map(int, raw_input().split()):
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
if len(dic) > 3:
	print "No"
elif len(dic) == 3:
	vals = []
	for i in dic:
		vals.append(i)
	if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
		print "No"
	elif max(dic.values()) - min(dic.values()) >= 1:
		print "No"
	else:
		print "Yes"
elif len(dic) == 2:
	if n == 3 and 0 in dic and dic[0] == 1:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic:
		print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

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

flag = 0
even = []
odd = []
for i in a:
    if i%2 == 0:
        even.append(i)
    else:
        odd.append(i) 

if n%2 == 1:
    if len(odd) >= 1:
        flag = 1
    else:
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
            if aa in a:
                count += 1
            if count < 2:
                flag = 1
                break

else:
    if len(odd)/2 != len(even):
        flag = 1
        for i in range(n):
            count = 0
            for j in range(i, n):
                aa = a[i]^a[j]
            if aa in a:
                count += 1
            if count < 2:
                flag = 1
                break

if flag == 1:
    print("No")
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
l=[]
l.append(a[0])
for i in range(1,n):
    if a[i]^a[0] in a:
        x=a[i]^a[0]
        l.append(a[i])
        l.append(x)
        break
if len(l)!=3:
    print("No")
else:
    if l[0]==l[1]:
        if n%3==0:
            if a.count(l[0])==(n//3)*2 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[0])==(n//3)*2+2 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
    if l[0]==l[2]:
        if n%3==0:
            if a.count(l[0])==(n//3)*2 and a.count(l[1])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[0])==(n//3)*2+1 and a.count(l[1])==n//3+1:
                print("Yes")
            else:
                print("No")
    if l[2]==l[1]:
        if n%3==0:
            if a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[1])==(n//3)*2 and a.count(l[0])==n//3+1:
                print("Yes")
            else:
                print("No")
        else:
            if a.count(l[1])==(n//3)*2+1 and a.count(l[0])==n//3+1:
                print("Yes")
            else:
                print("No")
    else:
        if n%3==0:
            if a.count(l[0])==n//3 and a.count(l[1])==n//3 and a.count(l[2])==n//3:
                print("Yes")
            else:
                print("No")
        elif n%3==1:
            if a.count(l[0])==n//3+1 and a.count(l[1])==n//3 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3 and a.count(l[2])==n//3+1:
                print("Yes")
            else:
                print("No")
        elif n%3==2:
            if a.count(l[0])==n//3+1 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3:
                print("Yes")
            elif a.count(l[0])==n//3+1 and a.count(l[1])==n//3 and a.count(l[2])==n//3+1:
                print("Yes")
            elif a.count(l[0])==n//3 and a.count(l[1])==n//3+1 and a.count(l[2])==n//3+1:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
import copy
N=int(input())
a_list=list(map(int,input().split()))
if N%3!=0:
  print("No")
else:
    a=set(a_list)
    a=list(a)
    if 0 in a:
            if len(a) ==2:
                if a_list.count(0)==len(a_list)//3:
                    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:
import itertools

N = int(input())
a = list(int(i) for i in input().split())

for k in range(3, N + 1):
    cnt = 0
    for p in itertools.permutations(a, k):
        for i in range(k):
            if i == 0:
                if p[k - 1] ^ p[i + 1] != p[i]:
                    if len(p) - 1 == cnt:
                        print("No")
                        exit()
                    break
            elif i == k - 1:
                if p[i - 1] ^ p[0] != p[i]:
                    if len(p) - 1 == cnt:
                        print("No")
                        exit()
                    break
                else:
                    # a = (set(a) - set(p))
                    # a.add(p[i - 1])
                    # a.add(p[0])
                    if k == N:
                        print("Yes")
                        exit()
            else:
                if p[i - 1] ^ p[i + 1] != p[i]:
                    if len(p) - 1 == cnt:
                        print("No")
                        exit()
                    break
        cnt = cnt + 1

Submission status: Wrong Answer

Solution code:
N = int(input())
arr = list(map(int, input().split()))
ans = 'Yes'

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:
n = int(input())
a = [int(i) for i in input().split()]

if 0 in a:
    set_a = list(set(a))
    if len(set(a)) == 1:
        print("Yes")
    elif len(set(a)) == 2:
        if a.count(set_a[0]) == 2*a.count(set_a[1]):
            print("Yes")
        else:
            print("No")
    else:
        print("No")

else:
    if n%3 != 0:
        print("No")

    else:
        if len(set(a)) != 3 or a.count(list(set(a))[0]) != int(n/3) or a.count(list(set(a))[1]) != int(n/3) or a.count(list(set(a))[2]) != int(n/3):
            print("No")

        else:
            a = list(set(a))
            a = sorted(a)

            if a[1]-a[0] == a[2]-a[1]:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    array = list(map(int, input().split()))
    set_array = list(set(array))
    if len(set_array) == 1 and set_array[0] == 0:
        return "Yes"
    if N != len(array):
        return "No"
    if N%3 != 0:
        return "No"
    if len(set_array) != 3:
        return "No"
    for i in range(2):
        if array.count(set_array[i]) != array.count(set_array[i+1]):
            return "No"
    x = set_array[0]
    y = set_array[1]
    z = set_array[2]
    if x ^ y == z and y ^ z == x and x ^ z == y:
        return "Yes" 
    return "No"

print(main())

Submission status: Wrong Answer

Solution code:
import sys
import itertools
n=int(input())
l=list(map(int,input().split()))
l.sort()
s=set(l)
if len(s)>=4 :print("No");sys.exit()
if len(s)==1:print("Yes" if 0 in s else "No");sys.exit()
s=list(s)
if len(s)==2:
  if 0 not in s:print("No");sys.exit()
  if n%3==1:
    if l.count(0)==(n-1)//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
  elif n%3==2:
    if l.count(0)==(n+1)//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
  elif n%3==0:
    if l.count(0)==n//3:print("Yes");sys.exit()
    else:print("No");sys.exit()
flag=0
for i in itertools.permutations(s):
  if i[0]^i[2]==i[1] and i[1]^i[2]==i[0] and i[0]^i[1]==i[2]:flag+=1
if flag==6:print("Yes")
else:print("No")

Submission status: Wrong Answer

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

l = a[0]
m = -1
n = -1
o = -1

for i in range(1,N):
    if a[i] != l and m == -1:
        m = a[i]
    if a[i] != l and a[i] != m and m != -1:
        n = a[i]
    if a[i] != l and a[i] != m and m != -1 and a[i] != n and n != -1:
        o = a[i]
        break

if o != -1:
    print("No")
elif (a.count(l)==a.count(m) and a.count(m)==a.count(n) and a.count(l)+a.count(m)+a.count(n) == N):
    print("Yes")
elif n == -1 and m != -1 and ((a.count(l) == a.count(m)*2 and l^m == l and a.count(l)+a.count(m)*2==N)or(a.count(l)*2 == a.count(m) and l^m == m and a.count(l)*2+a.count(m)==N)):
    print("Yes")
elif m == -1 and a.count(l) == N and l^l==l:
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
hat_list = list(map(int, input().split()))
#print(hat_list)
b_list = []
for h in hat_list:
    #print(format(h,'b').zfill(10))
    b_list.append(format(h,'b').zfill(17))
#print(b_list)
for n in range(17):
    test_list = []
    for b in b_list:
        test_list.append(b[n])
    if test_list.count('1') > 0:
        if test_list.count('1') != test_list.count('0') * 2:
            print("No")
            break
else:
    print("Yes")

Submission status: Wrong Answer

Solution code:
import collections
N = int(input())
W = list(map(int, input().split()))
c = dict(collections.Counter(W))

if len(c.keys()) == 1:
  if c.get(0, False) == False:
    print('No')
  else:
    print('Yes')
if len(c.keys()) == 2:
  num = list(c.values())
  num = sorted(num)
  if c[0]*2 == num[1]:
    print("Yes")
  else:
    print("No")
if len(c.keys()) == 3:
  num = list(c.values())
  if num[0] == num[1]:
    if num[0] == num[2]:
      print("Yes")
  else:
    print("No")
if len(c.keys()) >= 4:
  print("No")

Submission status: Wrong Answer

Solution code:
import copy
import bisect
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
a = list(map(int, input().split()))

M = len(format(max(a), 'b'))
first_a = format(a[0], 'b')
full_bit = (1 << M) - 1
candidate = []

for i in range(1, N):
	if a[0] | a[i] == full_bit:
		candidate.append(a[i])

tmp1 = a[0]
flag = False

for i in range(len(candidate)):
	tmp_list = copy.copy(a)
	tmp2 = candidate[i]
		
	for j in range(N):
		index = bisect.bisect_left(tmp_list, tmp1 ^ tmp2)
		
		if tmp1 ^ tmp2 == tmp_list[index]:
			tmp_list.pop(index)
			tmp1, tmp2 = tmp2, tmp1 ^ tmp2
			if j == N - 1:
				flag = True
				
if flag:
	print('Yes')
else:
	print('No')

Submission status: Wrong Answer

Solution code:
from sys import exit
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))

def noexit():
    print('No')
    exit()

def yesexit():
    print('Yes')
    exit()

setA = set(A)
if 0 in setA:
    if len(setA) == 1: yesexit()
    elif len(setA) == 2 and N%3 == 0: yesexit()
    else: noexit()

if N%3 != 0: noexit()
if len(setA) != 3: noexit()

listA = list(setA)
if listA[0]^listA[1] == listA[2]:
    new_list = [listA[0]]*(N//3) + [listA[1]]*(N//3) + [listA[2]]*(N//3)
    A.sort()
    new_list.sort()
    if A == new_list:
        yesexit()
    else:
        noexit()
else: noexit()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
li = list(map(int,input().split()))
flag = "No"
if(n % 3 == 0):
  li_uniq = list(set(li))
  if(len(li_uniq) == 3):
    check = li_uniq[0] ^ li_uniq[1]
    if(check == li_uniq[2]):
      a = li.count(li_uniq[0])
      b = li.count(li_uniq[1])
      c = li.count(li_uniq[2])
      if(a == b == c):
        flag = "Yes"
print(flag)

Submission status: Wrong Answer

Solution code:
### A

N = int(input())
a_all = list(map(int, input().split()))
t = list(set(a_all))

if len(a_all)==3:
    if (a_all[0]^a_all[1]==a_all[2]):
        print("Yes")
elif len(t)==2:
    a=0
    b=0
    for i in a_all:
        if i==t[0]:
            a+=1
        else:
            b+=1
    if(a == b*2 or  b == a*2):
        print("Yes")
    else:
        print("No")
elif len(t)==1:
    if t[0]^t[0]==t[0]:
        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()))
ans = "No"
Co = Counter(A)
if n % 3 != 0 : #3の倍数でない
    if len(Co.keys()) == 1 and list(Co.keys())[0] == 0:
        ans = "Yes" #要素の種類は1つかつその要素は0の場合のみOK
else :
    tr = n // 3
    Va = Co.values()
    #print(Va)
    if len(Va) == 3 :
        if Co.most_common()[0][1] == Co.most_common()[1][1] == Co.most_common()[2][1] == tr:
            ans = "Yes"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        ans = "No"
    elif len(Va) == 1 and Co.most_common()[0][0] == 1 :
        ans = "Yes"

print(ans)