How to identify value a matrix by considering others matrix
===

I have some matrices here :

    A = [ 1 2 3 4 0 0 0;
          0 0 1 2 3 4 0]
    B = [ 0 1 2 3 4 0 0;
          0 0 0 1 2 3 4]
    C = [ 1 2 3 4 0 0 0;
          0 1 2 3 4 0 0]

and I call matrices above as "initial matrix". then I have "matrix D" here :

    D = [ 1 2 3 4 0 0 0;
          1 2 3 4 0 0 0]

where I have to identify how many are value "1" in each row in matrix D which is not the same column with value ">3" in each row in matrix A,B,C which had been rearranged like the following example here.

    1 2 3 4 0 0 0
    0 0 1 2 3 4 0
        0 1 2 3 4 0 0 
        0 0 0 1 2 3 4
            1 2 3 4 0 0 0
            0 1 2 3 4 0 0 
                
                1 2 3 4 0 0 0
                1 2 3 4 0 0 0

and I wish my answer is 0, because value 1 for first and second row in the matrix D is the same column with one of some value in same column with value 1 which has value > 3 (4).

what is code to make answer like that guys? please help me, thanks before.

