count_0_k1[i,2] counts the number of transitions from zero to one in row i,
#count_1_k1[i,1] counts the number of transitions from one to zero in row i