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 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 False
        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("Yes")

Submission status: Wrong Answer

Solution code:
N = int(input())
data = {}
bits = 0
bit_table = [set() for _ in range(31)]
for a in map(int, input().split()):
	bits |= a
	if a in data:
		data[a] += 1
	else:
		data[a] = 1
	i = 0
	while a:
		if a % 2 == 1:
			bit_table[i].add(a)
		a //= 2
		i += 1

def pop(data, a):
	if a in data:
		if data[a] == 1:
			del data[a]
		else:
			data[a] -= 1
		return a
	else:
		return None

def check2(data0, a1, a2):
	if (a1 | a2) != bits:
		return False
	
	data = { k: data0[k] for k in data0 }
	a0 = a1
	pop(data, a1)
	pop(data, a2)
	
	while data:
		a3 = a1 ^ a2
		a4 = pop(data, a3)
		if a4 == None:
			return False
		a1 = a2
		a2 = a3
	return a0 == (a1 ^ a2)

def check(data):
	keys = data.keys()
	for a1 in keys:
		b = bits & (~a1)
		cands = None
		i = 0
		while b:
			if b % 2 == 1:
				if cands == None:
					cands = bit_table[i]
				else:
					cands &= bit_table[i]
			b //= 2
			i += 1
		
		if cands == None:
			cands = keys
		
		for a2 in cands:
			if a1 != a2 or data[a1] > 1:
				if check2(data, a1, a2):
					return True
	return False

if check(data):
	print("Yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
m=max(l)
if m==0:
  print("Yes")
else:
  if n%3!=0:
    print("No")
  else:
    l2=set(l)
    l1=[]
    for i in l2:
      l1.append(i)
    if len(l1)!=3:
      print("No")
    else:
      a=l1[0]
      b=l1[1]
      c=l1[2]
      l=sorted([a,b,c])
      m=l[2]
      l2=[]
      while m!=0:
        l2.append(m%2)
        m=m//2
      m1=l[1]
      l1=[]
      while m1!=0:
        l1.append(m1%2)
        m1=m1//2
      m0=l[0]
      l0=[]
      while m0!=0:
        l0.append(m0%2)
        m0=m0//2
      while len(l0)<len(l2):
        l0.append(0)
      while len(l1)<len(l2):
        l1.append(0)
      b=True
      for i in range(len(l2)):
        if l0[i]+l1[i]+l2[i]!=2 and l0[i]+l1[i]+l2[i]!=0:
          b=False
      if b:
        print("Yes")
      else:
        print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input().split())
A=a.count(a[0])
ans="Yes"
if n>3:
    for i in range(n):
        if a.count(a[i])!=A or a.count(a[i])==1:
            ans="No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort()

    import collections
    c = collections.Counter(a_list)
    keys = sorted(c.keys())
    nk = len(keys)

    dprint(c)
    dprint(keys)

    # a[0] からスタート
    found = False
    start = keys[0]
    second = 0
    third = 0
    for i in range(0, nk):

        # 同じ数字を使う場合はcountに気を付ける
        if i == 0 and c[keys[i]] == 1:
            continue

        center = keys[i]
        max = start + center

        for j in range(i, nk):
            right = keys[j]

            # 同じ数字を使う場合はcountに気を付ける
            if i == j and c[keys[i]] == 1:
                continue

            if right > max:
                # これより大きいところにはない
                break

            if right == start ^ center:
                found = True
                break
        if found == True:
            break

    if found == False:
        print("No")
        return

    c[start] = c[start] - 1
    c[center] = c[center] - 1
    c[right] = c[right] - 1

    # これで、0, second, third が決まったので、あとは順次決める
    left = center
    center = right
    dprint(start, left, center)

    cnt = 3
    while True:
        # N個作ったら終了
        if cnt == N:
            break

        # 次の数字
        right = left ^ center

        # 検索
        rcount = c.get(right, 0)
        if rcount == 0:
            print("No")
            return

        # 同じ数字の場合はカウントに気を付ける
        if right == left or right == center or left == center:
            if rcount == 1:
                print("No")
                return

        dprint("found", right, rcount)

        # update
        c[right] = c[right] - 1
        left = center
        center = right

        cnt += 1
        dprint("next", cnt, left, center)

    if start ^ left == center:
        print("Yes")
    else:
        dprint("last check failed", start, left, center)
        print("No")


solve()

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
inp = [int(x) for x in input().split()]
m = max(inp)
a = [format(x, '0' + str(len(str(format(m, 'b')))) + 'b') for x in inp]

def mk_pair(f):
    s11, s12 = '', ''
    s21, s22 = '', ''
    for c in f:
        cn = '1' if c == '0' else '0'
        s11 += c
        s12 += c if c == '0' else cn
        s21 += cn
        s22 += cn if c == '0' else c
    return (s11, s12), (s21, s22)

def axor(p1, p2):
    res = ''
    for c1, c2 in zip(p1, p2):
        res += '0' if c1 == c2 else '1'
    return res

def mk_multiset(a):
    ms = dict()
    for e in a:
        if e in ms:
            ms[e] += 1
        else:
            ms[e] = 1
    return ms

def check(a, p, first):
    sa = mk_multiset(a)
    sa[first] -= 1
    if sa[first] == 0:
        sa.pop(first)
    p1, p2 = p

    q1 = first
    q2 = first

    c1 = p1
    c2 = p2

    rest = len(sa)
    while True:
        n1 = axor(q1, c1)
        n2 = axor(q2, c2)
        if (n1 == n2 and n1 in sa and rest == 1):
            return True
        if (n1 in sa and n2 in sa):
            rest -= 2
            if (rest == 0):
                return n1 == c2 and n2 == c1
            sa[n1] -= 1
            sa[n2] -= 1
            if sa[n1] == 0:
                sa.pop(n1)
            if sa[n2] == 0:
                sa.pop(n2)
            q1 = c1
            q2 = c2
            c1 = n1
            c2 = n2
        else:
            return False

for p in mk_pair(a[0]):
    ans = check(a, p, a[0])
    if ans:
        print('Yes')
        break
else:
    print('No')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
if n%3!=0:
    print("No")
else:
    bina = []
    maxketa=0
    for i in range(len(a)):
        bina.append(format(a[i], 'b'))
        if maxketa<len(bina[i]):
            maxketa=len(bina[i])
    flag=1
    for i in range(maxketa):
        onecount=0
        for j in range(len(bina)):
            k = i-maxketa+len(bina[j])
            print(k)
            if k>=0:
                if bina[j][k]=="1":
                    onecount+=1
        print(onecount)
        if len(bina)*2/3!=onecount:
            if onecount!=0:
                flag=0
                print("No")
                break
       
    if flag==1:
        print("Yes")

Submission status: Wrong Answer

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

def all_zero(a):
    for e in a:
        if e != 0:
            return False
    return True

def three_mod_same(a):
    for i in range(len(a)):
        if i - 3 >= 0 and a[i] != a[i - 3]:
            return False
    return True

if N % 3 != 0:
    if all_zero(a):
        print("Yes")
    else:
        print("No")
else:
    p = itertools.permutations(a[:3], 3)
    yes = False
    for permed_a in p:            
        good_perm = True
        for i in range(3):
            if permed_a[(i + 1) % 3] != (permed_a[i] ^ permed_a[(i + 2) % 3]):
                good_perm = False
                break
        if good_perm:
            yes = True
            break
    if not yes:
        print("No")
    else:
        if three_mod_same(a):
            print("Yes")
        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 = "No"
    elif len(Va) == 2 and Co.most_common()[0][1] == 2 * tr :
        ans = "Yes"
    elif len(Va) == 1 and Co.most_common()[0][0] == 1 :
        ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
P=int(input())
A=[int(i) for i in input().split(" ")]
ans=0
if P%3==0:
	if len(set(A))==3:

		if A.count(A[0])==P/3:
			n=A[0]
			A.remove(A[0])
			m=A[0]
			A.remove(A[0])
			l=A[0]
			if A.count(A[0])==P/3:
				if l==n|m:ans=1


if ans==1:
	print("yes")
else:
	print("No")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(len(a)):
    if i+1 == len(a):
        if (a[i-1] ^ a[0]) == a[i]:
            c += 1
    else:
        if (a[i-1] ^ a[i+1]) == a[i]:
            c += 1           
            

print("Yes")

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 False
        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 = False
            break
        else:
            break
    else:
        continue
    break

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
arr=[]
for i in range(0,N+1):
    LF=(i-1)%N if (i-1) > (N-1) else (i-1)
    RI=(i+1)%N if (i+1) > (N-1) else (i+1)
    MI=i%N if i > (N-1) else i
    aaa = str(int(bin(A[LF]).split("b")[1])+int(bin(A[RI]).split("b")[1]))
    bbb = "".join(list(map(lambda x:str(int(x)%2),aaa)))
    arr.append(int(bbb)==int(bin(A[MI]).split("b")[1]))

print("Yes" if all(arr[0:N]) else "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

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

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

Submission status: Wrong Answer

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

def xor(a,b):
    x = 0
    ma = max(len(str(a)),len(str(b)))
    for i in range(ma):
        a = str(a).rjust(ma,"0")
        b = str(b).rjust(ma,"0")     
        if a[-i-1] != b[-i-1]:
            x+= 10**i
        else:
            pass
    return x

bin_l = []
for i in lists:
    a = bin(i)
    b = int(a[2:])
    bin_l.append(b)

if len(bin_l)%3 ==0 and len(set(bin_l)) == 3:
    l = list(set(bin_l))
    print(l)
    
    if l[0] == xor(l[1],l[2]) and l[1] == xor(l[0],l[2]) and l[2] == xor(l[0],l[1]):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Submission status: Wrong Answer

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

N = int(input())
a = set(map(int, input().split()))

flag = True
if len(a) != 3:
    flag = False
if flag:
    a = sorted(a)
    if not(a[0]^a[2] == a[1] and  a[1]^a[0] == a[2] and  a[2]^a[1] == a[0]):
        flag = False

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

Submission status: Wrong Answer

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

if len(set(a)) == 1 and a[0] == 0:
    print('Yes')
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] == c[2] == N//3:
            print('Yes')
        else:
            print('No')
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) == N//3*2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    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)
	tmp1 = a[0]
	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:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	if N != 3:
		print("No")
		return

	ans_arr = [[1, 2, 3], [0, 1, 3], [0, 2, 3], [0, 1, 2]]
	val_set = set()
	for a in A:
		val_set.add(a)
	possible = False
	for arr in ans_arr:
		this_ans = True
		for a in arr:
			if not a in val_set:
				this_ans = False
		if this_ans:
			possible = True
			break
	if possible:
		print("Yes")
	else:
		print("No")


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
first = A[-1]
dic = {}
dp = {}
for a in A[:-1]:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
import sys
sys.setrecursionlimit(10**5)
def DP(count,pre,num,f,s,dic):
    temp = pre ^ num
    if count == N - 3:
        if dic[temp] == s:
            return True
        else:
            return False
    if (pre,num) in dp:
        return dp        
    if temp in dic:
        if dic[temp] >= 1:
            dic[temp] -= 1
            dp[(pre,num)] = DP(count + 1,num,dic[temp],f,s,dic)
            return dp[(pre,num)]
def main():
    flag = False
    for a in A[:-1]:
        if first ^ a in dic:
            if dic[first ^ a] >= 2:
                tdic = dic.copy()
                flag = DP(0,a,a ^ first,first,a,tdic) or flag
                if flag:
                    print('Yes')
                    return
    print('No')
    return
if N == 3:
    if A[0] ^ A[1] == A[2]:
        print('Yes')
else:
    main()

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()
    g = list(c.keys())
    if g[0] ^ g[1] == g[2]:
        print("Yes")
    else:
        print("No")

Submission status: Wrong Answer

Solution code:
from collections import Counter

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

c = Counter(A)
K = c.keys()

ans = "No"
if len(K)==3:
    B = []
    for k in K:
        B.append(k)
    if c[B[0]]==c[B[1]] and c[B[1]]==c[B[2]] and B[0]^B[1]==B[2]:
        ans = "Yes"
elif len(K)==2:
    B = []
    for k in K:
        B.append(k)
    if c[B[0]]==c[B[1]] and (B[0]==0 or B[1]==0):
        ans = "Yes"
elif len(K)==1:
    for k in K:
        if k==0:
            ans = "Yes"

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    array = list(map(int, input().split()))
    set_array = list(set(array))
    if N != len(array):
        return "No"
    if N < 3:
        return "No"
    if len(set_array) == 1 and set_array[0] == 0:
        return "Yes"
    
    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:
N = int(input())
a = list(map(int, input().split()))[:N]
a.append(a[0])

xorNeighbor = 0
xorNeighborS = 0
nonZero = []

for i in range(1, len(a)-1):
    xorNeighbor = a[i-1] ^ a[i] ^ a[i+1]
    xorNeighborS ^= xorNeighbor
    if xorNeighbor:
        nonZero.append(xorNeighbor)
    #print(nonZero, xorNeighborS)

if len(nonZero) == 0:
    print("Yes")
else:
    if xorNeighborS:
        nonZero.append(xorNeighborS)
    #print(nonZero)
    try:
        while len(nonZero):
            removeVal = nonZero[0]
            nonZero.remove(removeVal)
            nonZero.remove(removeVal)
        print("Yes")
    except:
        print("No")

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

debug = True
debug = False


def dprint(*objects):
    if debug == True:
        print(*objects)


def solve():
    N = int(input())
    a_list = list(map(int, input().split()))
    a_list.sort()

    import collections
    c = collections.Counter(a_list)
    keys = sorted(c.keys())
    nk = len(keys)

    dprint(c)
    dprint(keys)

    # a[0] からスタート
    found = False
    start = keys[0]
    second = 0
    third = 0
    for i in range(1, nk):
        center = keys[i]
        max = start + center

        for j in range(i, nk):
            right = keys[j]

            # 同じ数字を使う場合はcountに気を付ける
            if i == j and c[keys[i]] == 1:
                continue

            if right > max:
                # これより大きいところにはない
                break

            if right == start ^ center:
                found = True
                break
        if found == True:
            break

    if found == False:
        print("No")
        return

    c[start] = c[start] - 1
    c[center] = c[center] - 1
    c[right] = c[right] - 1

    # これで、0, second, third が決まったので、あとは順次決める
    left = center
    center = right
    dprint(start, left, center)

    cnt = 3
    while True:
        # N個作ったら終了
        if cnt == N:
            break

        # 次の数字
        right = left ^ center

        # 検索
        rcount = c.get(right, 0)
        if rcount == 0:
            print("No")
            return

        # 同じ数字の場合はカウントに気を付ける
        if right == left or right == center or left == center:
            if rcount == 1:
                print("No")
                return

        dprint("found", right, rcount)

        # update
        c[right] = c[right] - 1
        left = center
        center = right

        cnt += 1
        dprint("next", cnt, left, center)

    if start ^ left == center:
        print("Yes")
    else:
        dprint("last check failed", start, left, center)
        print("No")


solve()

Submission status: Wrong Answer

Solution code:
from collections import Counter
n = int(input())
l = list(map(int, input().split()))
cnt = Counter(l)
res = len(cnt) == 1 and 0 in cnt
if not res and n == 3:
    res = l[0] ^ l[2] == l[1]
if not res and n % 3 == 0:
    if len(cnt) == 3 and all(v == n // 3 for v in cnt.values()):
        x = list(cnt.keys())
        res = x[0] ^ x[2] == x[1]
print("Yes" if res else "No")

Submission status: Wrong Answer

Solution code:
N=int(input())
A = list(map(int,input().split()))
if(N % 3 != 0):
    print('No')
else:
    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 = 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 0 in dic and n%2 and dic[0] == n/2:
		print "Yes"
	else:
		print "No"
else:
	if 0 in dic.keys():
		print "Yes"
	else:
		print "No"

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import collections

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

c = collections.Counter(a_list)

#print(len(c.keys()))

if len(c.keys()) != 3:
    print("No")
    quit()
    
ans_list = list(c.keys())
count_list = list(c.values())

if ans_list[0] == ans_list[1] ^ ans_list[2]:
    if count_list[0]==count_list[1]==count_list[2]:
        print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
import itertools
import sys

N = int(input())
A_list = list(map(int,input().split()))
# A_list = [1,2,3] * 300000
B_list = list()
for i in A_list:
	B_list.append(bin(i))

bin_0 = bin(A_list[0])
bin_2 = bin(A_list[2])

ans = bin(A_list[0]^A_list[2])
if ans in B_list:
	print('Yes')
	sys.exit()
else:
	count = 0 
	for i in itertools.combinations(A_list,2):
		count += 1
		if count <= 30:
			ans = bin(i[0]^i[1])
			if ans in B_list:
				print('Yes')
				sys.exit()
			else:
				continue
		else:
			break
print('No')

Submission status: Wrong Answer

Solution code:
import sys
N = int(input())
a_lis = sorted([int(_) for _ in input().split()])

def func(x, y):
    return x ^ y

def finish(ans, a_lis_item):
    if ans != a_lis_item:
        print('No')
        sys.exit()

for i, a in enumerate(a_lis):
    if i == 0:
        ans = func(a_lis[N - 1], a_lis[1])
    elif i == N - 1:
        ans = func(a_lis[0], a_lis[N - 2])
    else:
        ans = func(a_lis[i - 1], a_lis[i + 1])
    finish(ans, a_lis[i])

print('Yes')

Submission status: Wrong Answer

Solution code:
import numpy as np

n = int(input())
arr = list(map(int,input().split()))
d = {}

for a in arr:
    if a not in d:
        d[a] = 1
    else:
        d[a] += 1


if len(d) == 1:
    if 0 in d:
        print("Yes")
elif len(d) == 2:
    if n%3 != 0:
        print("No")
    elif 0 in d:
        flag = True
        for key in d.keys():
            if key == 0:
                if not d[key] == n//3:
                    flag = False
            else:
                if not d[key] == 2*n//3:
                    flag=False
        if flag:
            print("Yes")
        else:
            print("No")
    else:
        print("No")

elif len(d) != 3:
    print("No")

else:
    if n % 3 != 0:
        print("No")
    else:
        tar = [0,0,0]
        num = [0,0,0]
        temp = 0
        for key in d.keys():
            tar[temp] = key
            num[temp] = d[key]
            temp+=1
        if not (num[0] == num[1] and num[1] == num[2]):
            print("No")
        else:
            x1 = tar[0]^tar[1]
            x2 = tar[1]^tar[2]
            x3 = tar[0]^tar[2]

            if x1 == tar[2] and x2 == tar[0] and x3== tar[1]:
                print("Yes")
            else:
                print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input().split())
ans="Yes"
if n>3:
    for i in range(n-1):
        if a.count(a[i])!=a.count(a[i+1]) or a.count(a[i])==1:
            ans="No"
            break
print(ans)

Submission status: Wrong Answer

Solution code:
n = input()
a = list(map(int, input().split()))
res = []
for n in range(len(a)):
  if(n == (len(a) - 1)):
    res.append(a[n - 1]^a[0])
  else:
    res.append(a[n - 1]^a[n + 1])

rev = []
rev.append(res[0])
hoge = res[1:]
hoge.reverse()
rev.extend(hoge)

mes = "Yes"
for i, j in enumerate(res):
  if(i+1 != j):
    mes = ("No")
mes1 = "Yes"
for i, j in enumerate(rev):
  if(i+1 != j):
    mes1 = ("No")
if(mes == "Yes" or mes1 == "Yes"):
  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 False
        c[i^j]-=1
        i2 = j
        j = i^j
        i = i2
    return False

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:
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!=0:print("Yes")
else:print("No")

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(input().split())
ans="Yes"
if n>3:
    for i in range(n-1):
        if a.count(a[i])!=a.count(a[i+1]) or a.count(a[i])==1:
            ans="No"
            print(a.count(a[i]))
            print(ans)
            break
print(ans)

Submission status: Wrong Answer

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

flag = 0
for i in range(n):
    if((i+1) >= n):
        l = 0
    else:
        l = i + 1
        
    if((i-1) < 0):
        r = n - 1
    else:
        r = i - 1
    
    if(bin(a[i]) != bin(a[r] ^ a[l])):
        flag = 1
        break
        
if(flag == 0):
    print("Yes")
else:
    print("No")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
first = A[-1]
dic = {}
dp = {}
for a in A[:-1]:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
import sys
sys.setrecursionlimit(10**5)
def DP(count,pre,num,f,s,dic):
    temp = pre ^ num
    if (pre,num) in dp:
        return dp
    if count == N - 3:
        if dic[temp] == s:
            return True
        else:
            return False
        
    if temp in dic:
        if dic[temp] >= 1:
            dic[temp] -= 1
            dp[(pre,num)] = DP(count + 1,num,dic[temp],f,s,dic)
            return dp[(pre,num)]
def main():
    flag = False
    for a in A[:-1]:
        if first ^ a in dic:
            if dic[first ^ a] >= 2:
                tdic = dic.copy()
                flag = DP(0,a,a ^ first,first,a,tdic) or flag
                if flag:
                    print('Yes')
                    return
    print('No')
    return
if N == 3:
    if A[0] ^ A[1] == A[2]:
        print('Yes')
else:
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
#入力
#a = int(input())
#b,c = map(int, input().split())
#s = input()

N = int(input())
s = input()
a = np.asarray(s.split(), dtype=int)

#処理

d = {}
for val  in a:
    if val in d.keys():
        d[val] += 1
    else:
        d[val] = 1

keyNum = len(d.keys())
num = len(a)
keys = list(d.keys())

#条件１
if len(d.keys()) == 1 and 0 in d.keys():
    print ("Yes")
elif len(a) % 3 != 0:
    print ("No")
elif keyNum == 2:
    keys.sort()
    if keys[0] != 0:
        print ("No")
    elif d[0] != num//3:
        print ("No")
    else:
        keys1 = format(keys[1],'b')
        isAll1 = True
        for x in keys1:
            if x != '1':
                isAll1 = False
                break
        if isAll1:
            print ("Yes")
        else:
            print ("No")

elif keyNum != 3:
    print ("No")

else:
    key1 = format(keys[0],'040b')
    key2 = format(keys[1],'040b')
    key3 = format(keys[2],'040b')
    isA = True
    for k1,k2,k3 in zip(key1,key2,key3):
        kk1 = int(k1)
        kk2 = int(k2)
        kk3 = int(k3)
        goukei = kk1 + kk2 + kk3
        if not (goukei == 0 or goukei == 2):
            isA = False
            break
    
    if isA:
        print ("Yes")
    else:
        print ("No")