scala solution
```scala []
object Solution {
  def areSimilar(mat: Array[Array[Int]], k: Int): Boolean = {
    lazy val k1 = k%mat.head.length
    mat.zipWithIndex.forall{ case (a,i) =>
        lazy val (t,d) = a.iterator.splitAt(if(i%2==0) k1 else mat.head.length-k1 )
        a sameElements(d++t)
    }
  }
}
```
['Scala']