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: Accepted

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

a = A[0]
for i in range(1,N):
    a ^= A[i]
if a == 0: print('Yes')
else: print('No')

Submission status: Accepted

Solution code:
from collections import Counter


def solve(n, aaa):
    if all(a == 0 for a in aaa):
        return True

    if n % 3 != 0:
        return False

    cnt = list(Counter(aaa).items())
    if len(cnt) == 2:
        (a1, c1), (a2, c2) = cnt
        if c1 > c2:
            c1, c2 = c2, c1
        if c1 != n // 3 or c2 != n * 2 // 3:
            return False
        return a1 == 0

    if len(cnt) == 3:
        if any(c[1] != n // 3 for c in cnt):
            return False
        a1, a2, a3 = (c[0] for c in cnt)
        return a1 ^ a2 == a3

    return False


n = int(input())
aaa = list(map(int, input().split()))
print('Yes' if solve(n, aaa) else 'No')

Submission status: Accepted

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
xor = 0
for a in a_list:
    xor ^= a
if xor == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

a_xor = 0
for i in a:
  a_xor ^= i
if a_xor == 0:
  print("Yes")
else:
  print("No")

Submission status: Accepted

Solution code:
N = int(input())
lst = list(map(int, input().split()))
ans = 0
for i in range(N):
    ans = ans ^ lst[i]

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
L=[str(bin(i))[2:] for i in a]
dic=dict([(i,0) for i in range(32)])
for s in L:
    for i,c in enumerate(s[::-1]):
        if c=='1':
            dic[i]+=1
for i in dic.values():
    if i%2==1:
        print("No")
        exit(0)
else:
    print("Yes")

Submission status: Accepted

Solution code:
N = int(input())
a = [int(x) for x in input().split()]

dp = 0
for ai in a:
    dp ^= ai

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.append(a[0])
a.insert(0, a[-2])

ans = 0

for i in range(n):
    ans ^= a[i]

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

Submission status: Accepted

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

x = a[0]
for i in range(1, n):
    x ^= a[i]

if x == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

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

ans = 0
for a in A:
    ans = ans ^ a
if ans == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
s=a[0]
for i in range(1,n):
    s=s^a[i]
if s==0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
#coding:utf-8
from functools import reduce
def xor(a,b):
    return a^b
N = int(input())
ls = list(map(int,input().split()))
ans = reduce(xor,ls)
if ans==0:
    print ("Yes")
else:
    print ("No")

Submission status: Accepted

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

unq = list(set(nums))


def answer(ans):
    print(ans)
    exit()

if len(unq) > 3:answer("No")

if len(unq) == 3:
    a,b,c = unq
    if a ^ b ^ c != 0:answer("No")
    if nums.count(a) == nums.count(b) == nums.count(c):answer("Yes")
    else:answer("No")

if len(unq) == 2:
    a,b = sorted(unq)
    if a != 0:answer("No")
    if nums.count(a) * 2 == nums.count(b):answer("Yes")
    else: answer("No")

if len(unq) == 1:
    a = unq[0]
    if a != 0:answer("No")
    else:answer("Yes")

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
cnt=[0]*40
for val in arr:
  tbit=format(val,'b')[::-1]
  for i in range(len(tbit)):
    if tbit[i]=='1':
      cnt[i]+=1
for val in cnt:
  if val%2==1:
    print('No')
    break
else:
  print('Yes')

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
if N%2==1:
    s = 0
    for a in A:
        s^=a
    if s==0:
        print("Yes")
    else:
        print("No")
else:
    s1 = 0
    for a in A[::2]:
        s1 ^= a
    s2 = 0
    for a in A[1::2]:
        s2 ^= a
    if s1 == s2 == 0:
        print("Yes")
    else:
        print("No")

Submission status: Accepted

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

m = A[0]
for i in range(1, N):
    m ^= A[i]

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

Submission status: Accepted

Solution code:
n = int(input())
dat_a = map(int, input().split())
dat_a = list(dat_a)
res = dat_a[0]
for i in range(1,n):
    res ^= dat_a[i]
print("Yes" if res == 0 else "No")

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))
    tmp = 0
    for i in range(N):
        tmp ^= a[i]
    if tmp == 0:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Submission status: Accepted

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

tmp = 0
for a in A:
  tmp = tmp ^ a

ans = "No"
if tmp == 0:
  ans = "Yes"
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = a[0] ^ a[1]
for i in range(2, n):
    ans ^= a[i]
if ans == 0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
def solve():
  N = int(input())
  A = [int(i) for i in input().split()]
  v = 0
  for a in A: v^= a
  return 'Yes' if v == 0 else 'No'

print(solve())

Submission status: Accepted

Solution code:
n = int(input())

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

ans = A[0]

for i in range(1, n):
    ans ^= A[i]

if ans == 0:
    print('Yes')

else:
    print('No')

Submission status: Accepted

Solution code:
n = int(input())
a  = list(map(int, input().split()))
ans = 0
for i in range(n):
  ans ^= a[i]
if ans:
  print("No")
else:
  print("Yes")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
xor = 0
for num in a:
    xor ^= num
if xor == 0:
    print('Yes')
else:
    print('No')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
from fractions import gcd
from math import ceil, floor, sqrt
from copy import deepcopy
from collections import Counter, deque
import heapq
from functools import reduce
sys.setrecursionlimit(200000)
# local only
# if not __debug__:
#     fin = open('in_1.txt', 'r')
#     sys.stdin = fin
# local only
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template


def main():
    N = ii()
    A = lmi()
    a = 0
    for i in range(N):
        a = a ^ A[i]
    if a != 0:
        print('No')
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n=int(input())
p=input().rstrip().split(' ')
xor = 0;
for i in range(0,len(p)):
    xor = xor^int(p[i])
if xor==0:
    print("Yes")
else:
    print("No")

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = 0
for i in range(n):
  s ^= a[i]
if s == 0:
  print('Yes')
else:
  print('No')

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = LI()
    x = a[0]
    for i in a[1:]:
        x = x ^ i
    if x:
        print("No")
    else:
        print("Yes")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    a = LI()
    ans = 0
    for i in a:
        ans ^= i
    if not ans:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    A()

Submission status: Runtime Error

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

#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))
n = N // 3
dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = True

if len(dic) > 3:
    ans = False

elif len(dic) == 3:
    keys = dic.keys()
    for k in keys:
        if dic[k] != n:
            ans = False

    if (keys[0] ^ keys[1]) != keys[2]:
        ans = False

elif len(dic) == 2:
    for k in dic:
        if k == 0:
            if dic[k] != n:
                ans = False
        else:
            if dic[k] != n * 2:
                ans = False

else:
    keys = dic.keys()
    if not 0 in keys:
        ans = False

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

Submission status: Runtime Error

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

#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))
n = N // 3
dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = True

if len(dic) > 3:
    ans = False

elif len(dic) == 3:
    keys = dic.keys()
    for k in keys:
        if dic[keys] != n:
            ans = False

    if (keys[0] ^ keys[1]) != keys[2]:
        ans = False

elif len(dic) == 2:
    for k in dic:
        if k == 0:
            if dic[k] != n:
                ans = False
        else:
            if dic[k] != n * 2:
                ans = False

else:
    keys = dic.keys()
    if not 0 in keys:
        ans = False

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

Submission status: Runtime Error

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

#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))

dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = True

if len(dic) > 3:
    ans = False

elif len(dic) == 3:
    for k in dic:
        if dic[k] != N // 3:
            ans = False
            break

elif len(dic) == 2:
    keys = dic.keys()
    if 0 not in keys:
        ans = False
    if dic[keys[0]] != dic[keys[1]]:
        ans = False

else:
    key = dic.keys()
    if 0 not in keys:
        ans = False

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

Submission status: Runtime Error

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

#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))

dic = {}

for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1

ans = True

if len(dic) > 3:
    ans = False

elif len(dic) == 3:
    for k in dic:
        if dic[k] != N // 3:
            ans = False
            break

elif len(dic) == 2:
    keys = dic.keys()
    if 0 not in keys:
        ans = False
    if dic[keys[0]] != dic[keys[0]]:
        ans = False

else:
    key = dic.keys()
    if 0 not in keys:
        ans = False

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

Submission status: Runtime Error

Solution code:
from collections import*
n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C)
if l==3:f=(len(set(c[1]for c in C))>1)+n%3>0
elif l==2:f=(abs(C[1][1]-C[0][1])!=n//3)+n%3>0
else:f=(l!=1)+A[0]>0
print('YNeos'[f::2])

Submission status: Runtime Error

Solution code:
from collections import*
n,*A=map(int,open(0).read().split());C=Counter(A).items();f=1;l=len(C)
if l==3:f=(len(set(c[1]for c in C))>1)+n%3>0
elif l==2:f=(abs(C[1][1]-C[0][1])!=n//3)+n%3>0
else:f=(l!=1)*(A[0]>0)
print('YNeos'[f::2])

Submission status: Runtime Error

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

if N % 3 != 0:
    res = 'Yes'
    for i in range(N):
        if a_ls[i] != 0:
            res = 'No'
else:
    res = 'Yes'
    c = Counter(a_ls)
    if len(c) > 3:
        res = 'No'
    if len(c) == 3:
        if not list(c.values())[0] == list(c.values())[1] == list(c.values())[2]:
            res = 'No'
        for i in c.keys():
            for j in c.keys():
                for k in c.keys():
                    if i!=j and j!=k and k!=i and not i^j==k:
                        res = 'No'
    elif len(c) == 2:
        if not (list(c.values())[0] == N//3 or list(c.values())[1] == N//3):
            res = 'No'
        if list(c.values())[0] == N//3:
            if not c.keys()[0] == 0:
                res = 'No'
        if list(c.values())[1] == N//3:
            if not c.keys()[1] == 0:
                res = 'No'
    else:
        for i in range(N):
            if a_ls[i] != 0:
                res = 'No'
        
print(res)

Submission status: Runtime Error

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

if N % 3 != 0:
    res = 'Yes'
    for i in range(N):
        if a_ls[i] != 0:
            res = 'No'
else:
    res = 'Yes'
    c = Counter(a_ls)
    if len(c) > 3:
        res = 'No'
    if len(c) == 3:
        if not list(c.values())[0] == list(c.values())[1] == list(c.values())[2]:
            res = 'No'
        for i in c.keys():
            for j in c.keys():
                for k in c.keys():
                    if i!=j and j!=k and k!=i and not i^j==k:
                        res = 'No'
    elif len(c) == 2:
        if not (list(c.values())[0] == N//3 or list(c.values())[1] == N//3):
            res = 'No'
        if list(c.values())[0] == N//3:
            if not c.key()[0] == 0:
                res = 'No'
        if list(c.values())[1] == N//3:
            if not c.key()[1] == 0:
                res = 'No'
    else:
        for i in range(N):
            if a_ls[i] != 0:
                res = 'No'
        
print(res)

Submission status: Runtime Error

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

if N % 3 != 0:
    res = 'Yes'
    for i in range(N):
        if a_ls[i] != 0:
            res = 'No'
else:
    res = 'Yes'
    c = Counter(a_ls)
    if len(c) > 3:
        res = 'No'
    if len(c) == 3:
        if not list(c.values())[0] == list(c.values())[1] == list(c.values())[2]:
            res = 'No'
        for i in c.keys():
            for j in c.keys():
                for k in c.keys():
                    if i!=j and j!=k and k!=i and not i^j==k:
                        res = 'No'
    else:
        for i in range(N):
        if a_ls[i] != 0:
            res = 'No'
        
print(res)

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())

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


if len(a) >= 4:
    ans = False

elif len(a) == 3:
    a, b, d = a
    if c[a] == c[b] == c[d] and a^b = c and c^b == a and a^c == b:
        ans = True
    else:
        ans = False

elif len(a) == 2:
    a, b = sorted(a)
    if a == 0 and c[a] == N/3 and c[b] == (N/3)*2:
        ans = True
    else:
        ans = False

elif len(a) == 1:
    if sum(a) == 0:
        ans = True
    else:
        ans = False

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

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())

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


if len(a) >= 4:
    ans = False

elif len(a) == 3:
    ans = True
    for i in c.values():
        if i != N/3:
            ans = False
            break

elif len(a) == 2:
    a, b = sorted(a)
    if a == 0 and c[a] == N/3 and c[b] == (N/3)*2
        ans = True
    else:
        ans = False

elif len(a) == 1:
    if a == [0]:
        ans = True
    else:
        ans = False

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

Submission status: Runtime Error

Solution code:
from collections import Counter

N = int(input())

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


if len(a) >= 4:
    ans = False

elif len(a) == 3:
    ans = True
    for i in c.values:
        if i != N/3:
            ans = False
            break

elif len(a) == 2:
    if c.most_common()[0][0] == 0 and c.most_common()[0][1] == (3/N)*2 and c.most_common()[1][1] == N/3:
        ans = True
    else:
        ans = False

elif len(a) == 1:
    if a == [0]:
        ans = True
    else:
        ans = False

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

Submission status: Runtime Error

Solution code:
def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def is_match(caps):
  global N

  if 0 in caps.keys():
    if caps[0] == N:
      return True
  
  if N % 3 == 0:
    if 0 in caps.keys() and len(caps) == 2:
      if caps[0] == N//3:
        return True
    elif len(caps) == 3:
      x, y, z = caps.keys()
    
      if x ^ y ^ z == 0:
        if caps[x] == caps[y] == caps[z] == N//3:
        return True


# A - XOR Circle
N = int(input())
a = list(map(int, input().split()))

# 帽子の情報をdictに入れる
caps = get_caps(a)

if is_match(caps):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
def get_caps(a):
  dic = dict()

  for ai in a:
    dic.setdefault(ai, 0)
    dic[ai] += 1

  return dic


def is_match(caps):
  global N

  if 0 in caps.keys():
    if caps[0] == N:
      return True
  
  if N % 3 == 0:
    if 0 in caps.keys() and len(caps) == 2:
      if caps[0] == M//3:
        return True
    elif len(caps) == 3:
      x, y, z = caps.keys()
    
      if x ^ y ^ z == 0:
        return True


# A - XOR Circle
N = int(input())
a = list(map(int, input().split()))

# 帽子の情報をdictに入れる
caps = get_caps(a)

if is_match(caps):
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
from collections import Counter

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

c = Counter(a)
s = set(a)
l = len(s)

if l == 1 and a[0] == 0:
    print('Yes')
elif len(a) % 3 == 0:
    if l == 2 and c[0] == n // 3:
        print('Yes')
    elif l == 3:
        if s[0] ^ s[1] ^ s[2] == 0:
            tmp = c[a[0]]
            if all(x == tmp for x in c.values()):
                print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Submission status: Runtime Error

Solution code:
import sys
from random import shuffle
from collections import deque

input = sys.stdin.buffer.readline

class LCA:
    "0-indexed"

    def __init__(self, adj):  
        N = len(adj) 
        parent = [-1] * N
        self.depth = [0] * N
        q = deque([0])
        while q:
            node = q.popleft()
            for next_node in adj[node]:
                if parent[node] != next_node:
                    parent[next_node] = node
                    q.append(next_node)
                    self.depth[next_node] = self.depth[node] + 1
                        
        self.ancestor = [parent] #self.ancestor[k][u]はuの2**k先の祖先。
        k = 1
        while (1 << k) < N:
            anc_k = [0] * N
            for u in range(N):
                if self.ancestor[-1][u] == -1:
                    anc_k[u] = -1
                else:
                    anc_k[u] = self.ancestor[-1][self.ancestor[-1][u]]
            self.ancestor.append(anc_k)
            k += 1

    def lca(self, u, v):
        if self.depth[u] < self.depth[v]:
            u, v = v, u
        for k, bit in enumerate(reversed(format(self.depth[u]-self.depth[v], 'b'))):
            if bit == '1':
                u = self.ancestor[k][u]
        if u == v:
            return u
        for anc in reversed(self.ancestor):
            if anc[u] != anc[v]:
                u = anc[u]
                v = anc[v]
        return self.ancestor[0][u]



N, M = map(int, input().split())
ABs = [tuple(map(int, input().split())) for _ in range(M)]
shuffle(ABs)

if M % 2 == 1:
    print(-1)
    exit()

inv_ABs = [dict() for _ in range(N+1)]
for i, (A, B) in enumerate(ABs):
    inv_ABs[A][B] = i
    inv_ABs[B][A] = i

reverse_ABs = [False] * M

iseven = [True] * (N+1)
for A, B in ABs:
    if not iseven[B]: # B -> A
        iseven[B] = True
        reverse_ABs[inv_ABs[A][B]] = True
    else:
        iseven[A] = (not iseven[A])

for A, B in ABs:
    if not iseven[A] and not iseven[B]:
        iseven[A] = True
        iseven[B] = True
        reverse_ABs[inv_ABs[A][B]] = (not reverse_ABs[inv_ABs[A][B]])

for A, B in ABs:
    if not iseven[A] and not iseven[B]:
        iseven[A] = True
        iseven[B] = True
        reverse_ABs[inv_ABs[A][B]] = (not reverse_ABs[inv_ABs[A][B]])

# 気合で木にする。（LCAを使いたいから。）
q = [1]
pseudo_parent = [0] * (N+1)
pseudo_parent[1] = 1
pseudo_adj = [[] for _ in range(N)] #This is 0-indexed.
while q:
    nq = []
    for v in q:
        for nv in inv_ABs[v]:
            if pseudo_parent[nv] == 0:
                pseudo_parent[nv] = v
                pseudo_adj[v-1].append(nv-1)
                pseudo_adj[nv-1].append(v-1)
                nq.append(nv)
    q = nq

lca = LCA(pseudo_adj)

odd_nodes = set((i for i, e in enumerate(iseven) if not e))
while odd_nodes:
    u = odd_nodes.pop()
    v = odd_nodes.pop()
    a = lca.lca(u-1, v-1) + 1
    while u != a:
        p = pseudo_parent[u]
        reverse_ABs[inv_ABs[u][p]] = (not reverse_ABs[inv_ABs[u][p]])
        u = p
    while v != a:
        p = pseudo_parent[v]
        reverse_ABs[inv_ABs[v][p]] = (not reverse_ABs[inv_ABs[v][p]])
        v = p    
    # assert len(odd_nodes) % 2 == 0

for rflg, (A, B) in zip(reverse_ABs, ABs):
    if rflg:
        print(B, A)
    else:
        print(A, B)

Submission status: Runtime Error

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

from collections import Counter

c=Counter(a)

v=list(c.values())
k=list(c.keys())

v=sorted(v)

ans='Yes'
if len(k)==3:
    for i in range(3):
        if v[i]!=n/3:
            ans='No'
            break
elif len(k)==2:
    for j in range(2):
        if v[j]!=n/3 and j==0:
            ans='No'
        elif v[j]!=2*n/3 andj==1:
            ans='No'
elif len(k)==1 and k[0]==0:
    ans='Yes'
else:
    ans='No'

print(ans)

Submission status: Runtime Error

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

from collections import Counter

c=Counter(a)

if len(list(c.keys())) ==3:
    if list(c.values())==[n//3,n//3,n//3]:
        print('Yes')
elif len(list(c.keys()))==2:
    if c.most_common()[0][1]==2*n//3:
        print('Yes')
elif len(list(c.keys()))==1:
    if c.keys()[0]==0:
        print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
if sum(A) ==0: #すべてゼロ
  print("Yes")
  exit()

if N%3 != 0:
  print("No")
else:
  dic = {}
  for x in A:
    if x in dic:
      dic[x] += 1
    else:
      dic[x] = 1
  V = list(dic.values())
  if V[0] == V[1] and V[1] == V[2]:
    K = list(dic.keys())
    if K[0]^K[1] == K[2] and K[1]^K[2] == K[0] and K[2]^K[0] == K[1]:
      print("Yes")
    else:
      print("No")
  else:
    print("No")

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys

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

# 全て0ならYes
if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()

# 3つずつ循環していなければNo
if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(arr)

# 2種類の場合
if len(c) == 2:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()

# 3種類の場合
elif len(c) == 3:
    result = list(c.values())
    if result[0] == result[1] == result[2]:
        ans1 = True
    else:
        ans1 = False
else:
    print("No")
    sys.exit()

result = list(c.keys())
ans2 = result[0] == result[1] ^ result[2] and result[1] == result[0] ^ result[2] and result[2] == result[0] ^ result[1]

print("Yes" if ans1 and ans2 else "No")

Submission status: Runtime Error

Solution code:
from collections import Counter
import sys

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

# 全て0ならYes
if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()

# 3つずつ循環していなければNo
if n % 3 != 0:
    print("No")
    sys.exit()

c = Counter(arr)

# 2種類の場合
if len(c) == 2:
    if c[0] == n // 3:
        print("Yes")
        sys.exit()

# 3種類の場合
elif len(c) == 3:
    result = list(c.values())
    if result[0] == result[1] == result[2]:
        ans1 = True
    else:
        ans1 = False
else:
    ans1 = False

result = list(c.keys())
ans2 = result[0] == result[1] ^ result[2] and result[1] == result[0] ^ result[2] and result[2] == result[0] ^ result[1]

print("Yes" if ans1 and ans2 else "No")

Submission status: Runtime Error

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

if all([x == 0 for x in arr]):
    print("Yes")
    sys.exit()

if n % 3 != 0:
    print("No")
    sys.exit()

# 排他的論理和になっているか
ans1 = arr[0] == arr[1] ^ arr[2] and arr[1] == arr[0] ^ arr[2] and arr[2] == arr[0] ^ arr[1]

# 3つずつ循環しているか
ans2 = all([x == arr[0] for x in arr[0::3]]) and all([x == arr[1] for x in arr[1::3]]) and all([x == arr[2] for x in arr[2::3]])

print("Yes" if ans1 and ans2 else "No")

Submission status: Runtime Error

Solution code:
from collections import*
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
  ans^=i
a=dict(Counter(a))
ak=list(a.keys())
if len(a)==1 and ak[0]!=0:ans=1
elif len(a)==2 and a.get(0)!=n//3:ans=1
elif len(a)==3 and not(a[ak[0]]==a[ak[1]]==a[ak[2]]==n//3):ans=1
elif len(a)>3:ans=1
print(['Yes','No'][ans])

Submission status: Runtime Error

Solution code:
from collections import*
n=int(input())
a=dict(Counter(list(map(int,input().split()))))
flag=1
if n%3:flag=0
elif len(a)==1 and a.key()[0]!=0:flag=0
elif len(a)==2 and a.get(0)!=n//3:flag=0
elif len(a)==3 and not(a.key()[0]==a.key()[1]==a.key()[2]==n//3):flag==0
print(['No','Yes'][flag])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [A[0],A[1],A[0]^A[1]]
flag = 0
for i in range(2,N):
    if A[i] not in C:
        flag = 1
        break
if flag==1:
    print("No")
else:
    if N%3==0:
        if A[0]==A[1]==0:
            print("Yes")
        elif A[0]==0 or A[1]==0:
            cnt = 0
            for i in range(N):
                if A[i]==0:
                    cnt += 1
            if cnt==N//3:
                print("Yes")
            else:
                print("No")
        else:
            C = {A[0]:0,A[1]:0,A[0]^A[1]:0}
            for i in range(N):
                C[A[i]] += 1
            if C[A[0]]==C[A[1]]==C[A[0]^A[1]]:
                print("Yes")
            else:
                print("No")
    else:
        if A[0]==A[1]==0:
            print("Yes")
        else:
            print("No")

Submission status: Runtime Error

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
li = list(map(int,input().split()))
se = set(li)
if len(se) == 1:
    if sum(se) == 0:
        print('Yes')
    else:
        priont('No')
elif len(se) == 2:
    a,b = sorted(se)
    if a == 0:
        if li.count(a) * 3 == n:
            print('Yes') # 0 count is equal 1
        else:
            print('No')
    else:
        print('No')
elif len(se) == 3:
    a,b,c = se
    if li.count(a) == li.count(b) == li.count(c):
        if a^b == c:
            print('Yes')
        else:
            print('No') # a xor b xor c = 0 is ok
    else:
        print('No')
else:
    print('No')

Submission status: Runtime Error

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

if A==[0]*N:
    print("Yes")
    exit()

T={}
for a in A:
    if a in T:
        T[a]+=1
    else:
        T[a]=1

F=True
for x in T:
    F&=(3*T[x]%N==0)

if not F:
    print("No")
    exit()

M=max(T,key=lambda x:T[x])
if 3*T[M]==N:
    x,y,z=list(T.keys())
else:
    x=y=M
    del T[M]
    z=tuple(T.keys())[0]

if x^y==z:
    print("Yes")
else:
    print("No")