import math


def MaxLevelRowCol(tile_size, max_wid, max_ht):
  """
  w == h == 256 -> (0, 0, 0)
  w == h == 512 -> (1, 1, 1)
  w == h == 1024 -> (2, 2, 2)
  Args:
    max_wid, max_ht: maxWidth,maxHeight
    tile_size: w/h of a tile in pixels (must be ^2 and square)
  Returns:
    (max_level, max_row, max_col): maximum for each
  """
  width_in_tiles = int(math.ceil(float(max_wid)/float(tile_size)))
  height_in_tiles = int(math.ceil(float(max_ht)/float(tile_size)))
  lh = math.ceil(math.log(width_in_tiles, 2))
  lw = math.ceil(math.log(height_in_tiles, 2))
  level = int(max(lh, lw))
  return (level, height_in_tiles-1, width_in_tiles-1)