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 Kotlin (1.0.0) (judge verdict: Accepted)

import java.util.Scanner
import java.util.ArrayList

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    var flag : Boolean = true
    var arraylist = ArrayList<Int>()
    for(i in 0 until N) {
        arraylist.add(sc.nextInt())
    }
    var A = -1
    var B = -1
    var C = -1
    var Acounter = 0
    var Bcounter = 0
    var Ccounter = 0
    for(i in 0 until N){
        val a = arraylist.elementAt(i)
        if(a == A){
            Acounter++
        }else if(a == B){
            Bcounter++
        }else if(a == C){
            Ccounter++
        }else if(A == -1){
            A = a
            Acounter++
        }else if(B == -1){
            B = a
            Bcounter++
        }else if(C == -1){
            C = a
            Ccounter++
        }else{
            flag = false
            break
        }
    }

    if(flag == false){
       println("No")
    }else{
        if(C != -1){
            if(Acounter == Bcounter && Bcounter == Ccounter){
               if(checkxor(A, B, C)){
                   println("Yes")
               }else{
                   println("No")
               }
            }else{
                println("No")
            }
        }else if(B != -1){
            if(Acounter == 2 * Bcounter){
               if(checkxor(A, A, B)){
                   println("Yes")
               }else{
                   println("No")
               }
            }else if(Bcounter == 2 * Acounter){
                if(checkxor(A, B, B)){
                    println("Yes")
                }else{
                    println("No")
                }
            }else{
                println("No")
            }
        }else{
            if(A == 0){
                println("Yes")
            }else{
                println("No")
            }
        }
    }
}

fun checkxor(i: Int, j: Int, k: Int) : Boolean{
    var i_bitlist = ArrayList<Char>()
    var j_bitlist = ArrayList<Char>()
    var k_bitlist = ArrayList<Char>()
    val zero : Char = '0'
    val one : Char = '1'
    var i_clone = i
    var j_clone = j
    var k_clone = k
    while(i_clone != 0){
        if(i_clone % 2 == 0){
            i_bitlist.add(zero)
        }else{
            i_bitlist.add(one)
            i_clone--
        }
        i_clone /= 2
    }
    while(j_clone != 0){
        if(j_clone % 2 == 0){
            j_bitlist.add(zero)
        }else{
            j_bitlist.add(one)
            j_clone--
        }
        j_clone /= 2
    }
    while(k_clone != 0){
        if(k_clone % 2 == 0){
            k_bitlist.add(zero)
        }else{
            k_bitlist.add(one)
            k_clone--
        }
        k_clone /= 2
    }
    var max_bitLength = i_bitlist.size
    if(j_bitlist.size > max_bitLength){
        max_bitLength = j_bitlist.size
    }
    if(k_bitlist.size > max_bitLength){
        max_bitLength = k_bitlist.size
    }
    val iListSize = i_bitlist.size
    for(m in iListSize-1 until max_bitLength-1){
       i_bitlist.add(zero)
    }
    val jListSize = j_bitlist.size
    for(m in jListSize-1 until max_bitLength-1){
        j_bitlist.add(zero)
    }
    val kListSize = k_bitlist.size
    for(m in kListSize until max_bitLength){
        k_bitlist.add(zero)
    }
    var isXor = true
    for(m in 0 until max_bitLength){
        if(i_bitlist.elementAt(m) == j_bitlist.elementAt(m)){
            if(k_bitlist.elementAt(m) != zero){
                isXor = false
                break
            }
        }else{
            if(k_bitlist.elementAt(m) != one){
               isXor = false
                break
            }
        }
    }
    return isXor
}