How is a 2D array stored in memory? Implement a function that calculates the linear memory offset of an element in either row-major or column-major storage. The function receives the array dimensions, element coordinates, and storage order, then returns the zero-based offset in the contiguous memory block.
def memory_offset(rows, cols, row, col, order):