https://www.codechef.com/problems/SC31 help in beginner- weapon value question

question: https://www.codechef.com/problems/SC31
my soln: https://www.codechef.com/viewsolution/34440398

the logic i used:-
so i thought that let us suppose there are 5 contestants, 2 contestants(s1 and s2) when fighting with each other
the end result would be same, i.e the array s1 or s2 would be same depending on who wins.
and i also thought the fighting is commutative and associative.
(same if s1 and s2 and then s1 and s3 or (s1 and s3) then s1 and s2))
==> so i made everyone fight with s1 contestant (s2 through sn) and used the fight function to calculate the value of count.
the value of count is initially the number of weapons s1 contains.
let us suppose s2 is fighting with s1, and now :-
// i used 2d array
if(s[i][j]==1)
{
if(s[0][j]==1)
{
count–;
s[0][j]=0;
}
else
{
count++;
s[0][j]=1;
}
}

pls help, thank you guys :smiley:
sorry if i am missing something obvious :sweat_smile: