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 C (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <stdbool.h>

int yes(int *a, int *b, int N, int C, int c[100][100][100])
{
    long j;
    for (j = 0; j < 1000000; j++)
    {
        //printf("%ld\n", j);
        if (c[j % 100][j / 100 % 100][j / 10000] == -1)
            break;
        else if (c[j % 100][j / 100 % 100][j / 10000] == C)
            return 0;
    }
    for (int i = 0; i < N; i++)
    {
        if (a[i] == C && (*b >> i) == 0x00)
        {
            *b |= 0x01 << i;
            return 1;
        }
    }
    c[j % 100][j / 100 % 100][j / 10000] = C;
    return 0;
}

int check(int *a, int N)
{
    // printf("A\n");
    int z[100][100][100] = {{{-1}}};
    // printf("B\n");
    for (int j = 1; j < N; j++)
    {
        int b = 0;
        int d = a[0];
        int e = a[j];
        int temp = 0;
        for (int i = 1; i < N; i++)
        {
            if (i == N - 1)
            {
                if (d ^ e != a[0])
                    return 0;
                return 1;
            }
            else if (yes(a, &b, N, d ^ e, z) == 1)
            {
                e ^= d;
                d ^= e;
                continue;
            }
            else
                break;
        }
    }
    return 0;
}

int main()
{
    int N;
    scanf("%d", &N);
    int *a = (int *)malloc(sizeof(int) * N);
    for (int i = 0; i < N; i++)
    {
        scanf("%d", &a[i]);
    }
    // printf("S\n");
    if (check(a, N) == 1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}

//                 ..-<??<<..
//              .?!      ..  .7(.                                                                                             ..Jv7<<(..
//           .?          ?Me    (1.                                                                                        .(Y'         ?7-.
//         ./            ..T!     (i                                                                                     .JY     .,        ?n,
//        .%          .MMMM:        4.                                                                                  .B        ?p         ?n
//       .%              JF          j,                                                                                .f         .M:         .S.
//       Z             .dMWMa.,       1.                                                                               J          .,           .S.
//      (!             JD   ?"=        S                                                                              .'           M[   (p      .n
//     .F                  .(-,        .[                                                                            .P    .M  ,   dF    ?b      (,
//     J                   (7TN         j                                                                            J     .T= .TNgM\     ?'      6
//    .F          .      .  .M$         ,|                                                                          .P                            ,<
//    .\      . .,M_    .#  .            L                                                                          .\                             b
//    J       # .M    .gMMMMM'           Z                                                                          d             .M               q
//    K      .F         JaJ-,            z                                                                         .P             (#               (_
//    #      .b   J      ?7"M|           j_                                                                        .]             d@               ,)
//    @       Wm.JF      ..d#            j!                        ..-vTYTTC<;;>;;<<<17TTI(..                      ,%             MF               ,[
//    #        ?"= N,    ("'             z~                    .JYC>;;;;;;;;;;;;;;;;;;;;;;;;<79a,                  (\             M%               ,[
//    N         .m+MMb                   Z                 ..VC;;;;;+++<;;;;;;;;;;;;;;;;;;;;;;;;?Th,               J)            .M{               J{
//    W_        MWN(M3                  .$               .J3;;;;;;jZ3;;;;;;;;;;;;;;;?C&+;;;;;;;;;;;;7a,            J[                              d
//    J]          T!                    .\             .9<;;;;;;jZ>;;;;+<;;;;;;;;;;;;;;v2;;;;;;;;;1;;;?h,          J]           .+p                P
//    ,b         .)                     J           ..9;;;;;;;;J3;;;;jI;;;;;;;;;;:;;:;;;j;;;:;;:;;<c;;;;?W,        ,b           d#                .%
//     W,        d!                     P          .9<;;;;;;;+v;;;;;J>;;;;;;;;;;;;;;;;;;<I;;;;;;;;;j<;;;;;?N,       H          JM                 J
//     .b       .N,                    .!        .X3;;;;;;;;+<;;;;;J;;;;;;;;;;;<;;:;<;;;;z;;;:;;:;;;I;;;:;;;Un      (;        .MaJ               .'
//      /L     .M@TN,.,               .P        .9;;;;<<;;;J;;;;;;J<;;;;;;;;;;;z;;;;<:;;;(2;;;;;;;;;j<;;;;;;;?h      4       .MM".M,            .%
//       ?[    .=  .TB!               (!      .d$;;;;;v;;<v;;;;;;j>;;;;;;;;;;;<1;;;:<(;:;;G;;;:;;:;;;I;:<<;;;;?h.    .L     .M#!   4,..MF      .%
//        ?L                          P      .d3;<~;;J<;<v;;;;;;;y;;  (;;;;;<j<jc;;;;_;;;;J+;;;;;;;;;j;;;c;;;;;?H.    ,n     !       77       .^
//         ?h,                       .%     .(>;! .;j3;;J;;;;;;<dD;;.. .;;;<(j;0h;;;;<<;;;+P;:;;<;;;;<c;;j;;:;;;?H,    ,h.                  .v
//          .Ta.                     ,[    ..C;;;;;;v;;J>;+;;;jY.$;;;;;;;;;<(Ij zc;;;+(;;:;S;;;<  ;;;;1;;j<;;;;;;?H.    .h                .J'
//            .Tm,                   .[    .3;;;;;;jC;j$;J>;;J^ .$;;;;;;;;;<(IZ  4;;:;z;;;;d;>;<...;;;j;;+c;;:;;;;dh.    ,)  .        ..J=
//               ?TWJ..     ..JZ<i(...<   .I<;;;;;;Z;+f;J<;</    X;;;;;;;;;<(G%   I;;;dc;;;Jcz;;;;;;;;+c;;I;;;;:;;;W[    .\ / ?777777!
//                   _?""""7!             JZ;;;;;;jC;J<J++&v??!  X+;;<;;;;;<(d! ~??k&JJH+;;jIz;;;;;;;:;I;;I;;;;;;;;jH.   .(^
//                                       .(3;;;;;;v;jRV$++=      jr;;u;;<;;;(d     ,c;<DTw+1$=;;;;:;;;;I;;O;;:;;:;;;d]  ?!
//                                       \,;;;;;;+$;dK 0I>       ,X<;?I;j<;;_I      ,+;w 1;j$O;:;;;;;;;1;;w;;;;;;;;;zb
//                                      , J;;;;;;j<jM!.z{         16;;?o<0+;<t       -+j  <jIz;;;:;;:;;+;;d<;;;:;;;;+d
//                                      \ R;;;;;;v;dn.JgggggggggJ,.l7+;1?J,G+u.Jxzzz<<?Z_  ?II;;;;;;;;;;;;d2;;;;:;;;;d-
//                                     . .D;;;;;;IjP     ...MNN#M]    ~?! ~ (4, dNMNNNNM#"BMHRz;;;:;;;;;;;dP;;;;;;;;;O]
//                                     _ .R;;;;;<>d      WHM#NMMM]           .MM@MMMMMMM\   (I;;;;;:;;:;;;Z@;;:;;:;;;IL
//                                       .R;;;;;+1]      G~_hJ~_J!           ,C<~h+v7"YH    ,<;;;;;;;;;;>;ZN;;;;;;;;;ID
//                                       .R;;;;;+J  ~.   ,h_...(^             S_._<..~J'    ,;;;:;;;;;;;>;}W;;;:;;:;;IR
//                                        H;;;;;+P         _!?!                71--(JY    _ (;;;;;;:;<;;>+:(<;;;;;;;;IP
//                                        W+;;;;j]                                         .d;;;:;;;:(;+>j Jc;;:;;;;+O$
//                                        zr;;;;Jb                                          S;;;;;;;<(;+<<.WI;;;:;;;j+[
//                                        .S;;;;?M,                                         D;;:;;;;~;;j;}Jd>;;;;;;;jz:
//                                         dx;;;;jH,                                       .C;;;:;;:(;;ZjZ<J>;:;;:;;2z
//                                         .b;;;;+<?N,                  ....               J<;;;;;;<(;+$v;;+;;;;;;;+C>
//                                          O+;;;;I;d@Tm,                  _               f;;:;;;;~;;d1I;;;;;;:;;;jj
//                                          .b;;;;?x?$;;<79mJ,.                           .$;;;;:;<(;jKj;;;;:;;;;;;d{
//                                           Jc;;;;1;I;;;;+1;?TWHQ+...           ....J7WMNM<;;;;;;~;+dDC;;;;;;;;:;<V
//                                           (4<;;;;I(+;;;+1;;;;;;jgMMM""HY         :  ,TM#;;;:;;<(<vMz;;+;;;:;;;;j]
//                                           ,<6;;;;j21;;;+I;;;;;;IMMD   %         .\  .;($;;;;;<(<vjE>;;c;;;;;;;;O}
//                                           ,>?s;;;;Vcc;;1>;;;;;<AY   .:         .r    Sz<;;;;;_+v;dC;;;I;;:;;:;+d:
//                                           ,<;Zo;;;j?J+;j;;;;;;d7T&, !__!.    .(=...  (f;;;;;<jvnjDz;;<>;;;;;;;jd_
//                                           ,;;I?n;;+c?z<Z;;;;;J<.(, <  >     .<.7    7d>;;;<~j3.(K<>;;+>;;;:;;;vd
//                                           ,;<1;<G<;1;<+P;;;+v(_.<(  (!(<. .z?~\    /.D;;;<(v+J1Cjj<;;+>;;;;;;+>X
//                                           J;+(;;;?++c;jC;;j3(~.~(..  .???CTV=    .>.v;;;<JI=~(<.(y;;;+>;;:;;;+;X
//                                           z;/.;;;;<1j;jI;j3(>.~.(-(  j.J+.._    .!,(>;<JC~._~<.~(@;;;+<;;;:;;<;W
//                                           f<!.;;;;;;<zIIJ'(t.~..~(.i  +!  ._ .-<,~(3+J>...~-!.~._K;;;j<;;;;;;;;V
//                                           D< .;;;;;;;;IX<.J.~.~...<.~,..! .+/<(!~(<~.(~.~._~.~.._S;;;+>;;:;;;;;U_
//                                          .I: .<;;;;;;;J:.~>..~.~~..(- !.?7~.?~.._.~.~:.~....~.~._u;;;+>;;;;:;;;w~