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: Wrong Answer)

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Stream;

public class Main {
    static final int MAX = 100100;
    InputStream in = System.in;
    PrintStream out = System.out;
    // static int dp[][] = new int[MAX][MAX];
    static int a[] = new int[MAX];
    static Map<Integer,Integer> mp = new HashMap<>();
    
    public void _main(String[] args) {
        _Scanner sc = new _Scanner(in);
        int n = sc.i();
        for(int i=0;i<n;i++) {
            a[i]=sc.i();
            if (!mp.containsKey(a[i])) mp.put(a[i],1);
            else mp.put(a[i],mp.get(a[i])+1);
        }
        if (n==3) {
            if ((a[0]^a[1])==a[2]&&(a[1]^a[2])==a[0]&&(a[2]^a[0])==a[1])
                exit("Yes");
            else exit("No");
        }
        if (n%3==0) {
            if (n>10&&n<1000) exit("No");
            boolean flag = true;
            int m = n/3;
            for (Map.Entry<Integer,Integer> item : mp.entrySet()) {
                if ((item.getValue()%m)!=0) {
                    flag = false;
                    break;
                }
            }
            if (flag) exit("Yes");
        }
        if (n%2==0) {
            int p = 2;
            boolean flag = true;
            for (Map.Entry<Integer,Integer> item : mp.entrySet()) {
                if ((item.getValue()%p)!=0) {
                    flag = false;
                    break;
                }
            }
            if (flag) exit("Yes");
        }
        exit("No");
    }

    void exit(String s) {
        out.println(s);
        System.exit(0);
    }
    class Counter<T> {
        Map<T,Integer> mp = new HashMap<>();
        int add(T t) {
            if (!mp.containsKey(t)) mp.put(t,1);
            else mp.put(t,mp.get(t)+1);
            return mp.get(t);
        }
        int get(T t) {return mp.get(t);}
        Stream<Pair<T,Integer>> entrySet() {
            return mp.entrySet().stream()
                .map(s -> new Pair<>(s.getKey(),s.getValue()));
        }
    }
    static void swap(int[]a,int i,int j){if(i!=j){a[i]^=a[j];a[j]^=a[i];a[i]^=a[j];}}
    static void swap(long[]a,int i,int j){if(i!=j){a[i]^=a[j];a[j]^=a[i];a[i]^=a[j];}}
    class _Scanner {
        private InputStream in;
        public _Scanner(InputStream in) {this.in=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;
        }
        final boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }
        final boolean isNum(String s) {
            try {
                Integer.parseInt(s);
                return true;
            } catch (NumberFormatException e) {
                return false;
            }
        }
        boolean hasNext() {
            while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }
        String s() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        long l() {
            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();
            }
        }
        int i() {
            long nl = l();
            if (nl<Integer.MIN_VALUE || nl>Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int)nl;
        }
        double d() {return Double.parseDouble(s());}
        char c() {return (char)readByte();}
    }
    public class Pair<T,K> {
        T a; K b;
        Pair(T _a, K _b) {a=_a;b=_b;}
    }
    class Queue<T> {
        ArrayDeque<T> Q = new ArrayDeque<T>();
        void push(T a) {Q.add(a);}
        T pop() {return Q.poll();}
        boolean isEmpty() {return Q.isEmpty();}
    }
    public static void main(String[] args) {
        new Main()._main(args);
    }
}