Looks like you still have some bugs:
rewritten data: 1 0 2 3 0 3
first row : 0 0 1 1 0 1
group a : 1 0 1
group b : 2 2 3
Group a and group b don't seem to match up with the data. Or I've misunderstood something.