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.

Solution in Java8 (OpenJDK 1.8.0) (judge verdict: Accepted)

import java.util.*;
import java.io.*;


public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        
        //...0110110110...or...000...でなければならない
        int n_cap = sc.nextInt();
        int[] written_num = new int[n_cap];
        
        boolean possible = true;
        boolean all0 = true;
        boolean[][] numB = new boolean[n_cap][32];
        
        for(int i=0; i<n_cap; i++){
            written_num[i] = sc.nextInt();
            if(written_num[i] > 0) all0 = false;
            numB[i] = intToBool(written_num[i]);
        }
        //show_b2d_array(numB);
        if(all0){
        }else if(n_cap%3 > 0){
            possible = false;
        }else{
            boolean[] is_all0d = new boolean[32];
            int count = 0;
            for(int dig=0; dig<32; dig++){
                count = 0;
                for(int i=0; i<n_cap; i++){
                    if(!numB[i][dig]) count++;
                }
                if(count == n_cap){
                    is_all0d[dig] = true;
                }else if(count == (n_cap/3)){
                    is_all0d[dig] = false;
                }else{
                    possible = false;
                    break;
                }
            }
            int[] g1 = new int[n_cap/3];
            int[] g2 = new int[n_cap/3];
            boolean g1found=false, g2_found = false;
            for(int dig=0; dig<32; dig++){
                //out.println(is_all0d[dig]);
                if(possible && (!is_all0d[dig])){
                    if(!g1found){
                        count=0;
                        for(int i=0; i<n_cap; i++){
                            if(!numB[i][dig]){
                                g1[count] = i;
                                count++;
                                g1found=true;
                            }
                        }
                    }else if(!g2_found){
                        for(int i=0; i<n_cap; i++){
                            if(!numB[i][dig]){
                                if(i!=g1[0]){
                                    g2_found=true;
                                    break;
                                }
                            }
                        }
                        count=0;
                        for(int i=0; i<n_cap; i++){
                            if(!numB[i][dig]){
                                if(g2_found){
                                    g2[count] = i;
                                    count++;
                                }else{
                                    if(i != g1[count]){
                                        possible=false;
                                        break;
                                    }
                                    count++;
                                }
                            }
                        }
                    }else{
                        int joinG = 0;
                        for(int i=0; i<n_cap; i++){
                            if(!numB[i][dig]){
                                if(i==g1[0]){
                                    joinG=1;
                                    break;
                                }else if(i==g2[0]){
                                    joinG=2;
                                    break;
                                }
                                break;
                            }
                        }
                        count=0;
                        for(int i=0; i<n_cap; i++){
                            if(!numB[i][dig]){
                                if(joinG==1){
                                    if(i != g1[count]){
                                        possible=false;
                                        break;
                                    }
                                }else if(joinG==2){
                                    if(i != g2[count]){
                                        possible=false;
                                        break;
                                    }
                                }else{
                                    if((i == g1[count]) || (i == g2[count])){
                                        possible=false;
                                        break;
                                    }
                                }
                                count++;
                            }
                        }
                    }
                }
            }
        }
        
        if(possible) out.println("Yes");
        else out.println("No");
        out.flush();
        //int count_continent=0;
        /*int[] ts_in = new int[n_v];
        int[] ts_out = new int[n_v];
        for(int i=0; i<n_v; i++){
            ts_in[i] = -1;
            ts_out[i] = -1;
        }*/
        
        /*ArrayDeque<Integer> todo = new ArrayDeque<>();
        todo.add(0);
        
        int deal_with = 0, tmp_togo=-1;
        while(todo.size() > 0){
            deal_with = todo.removeFirst();
            for(int i=0; i<plain_graph.get(deal_with).size(); i++){
                tmp_togo = plain_graph.get(deal_with).get(i);
                if(d_from1[tmp_togo] < 0){
                    d_from1[tmp_togo] = d_from1[deal_with]+1;
                    todo.add(tmp_togo);
                }
            }
        }
        
        for(int i=0; i<n_v; i++){
            out.println((i+1) + " " + d_from1[i]);
        }*/
    }
    
    static void show_b2d_array(boolean[][] dt){
    	for(int i=0; i<dt.length; i++){
    		for(int j=0; j<dt[0].length; j++){
    		    if(dt[i][j]) System.out.print("O");
    		    else System.out.print(".");
    		}
    		System.out.println();
    	}
    }
    
    public static boolean[] intToBool(int a){
        boolean[] bs = new boolean[32];
        for(int dig=0; dig<32; dig++){
            bs[dig] = ((a&(1<<dig)) > 0) ? true : false;
        }
        return bs;
    }
    
    
    
    public static int binarySearchMax(int[] dt, int target){
        int left=-1, right=dt.length;
        int mid=-1;
        
        while((right-left)>1){
            mid = left + (right-left)/2;
            
            if(dt[mid] <= target){
                left=mid;
            }else{
                right=mid;
            }
        }
        return left;  //target以下の最大のaddress
    }
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}