Row major formula for 2d array