code: def repartition(ddf, cumsum):
      # Calculate new optimal divisions and repartition the data
      # for load balancing.
  
      import math
  
      npartitions = ddf.npartitions
      count = math.ceil(len(ddf) / npartitions)
      new_divisions = [0]
      move_count = 0
      i = npartitions - 2
      for i in range(npartitions - 1):
          search_val = count - move_count
          index = cumsum[i].searchsorted(search_val)
          if index == len(cumsum[i]):
              index = -1
          elif index > 0:
              left = cumsum[i].iloc[index - 1]
              right = cumsum[i].iloc[index]
              index -= search_val - left < right - search_val
          new_divisions.append(
              new_divisions[i] + cumsum[i].iloc[index] + move_count
          )
          move_count = cumsum[i].iloc[-1] - cumsum[i].iloc[index]
      new_divisions.append(
          new_divisions[i + 1] + cumsum[-1].iloc[-1] + move_count - 1
      )
  
      return ddf.repartition(divisions=tuple(new_divisions))
  
imports: import numpy
  from dask.distributed import futures_of, default_client, wait
  from toolz import first
  import collections
  import dask_cudf
  from dask.array.core import Array
  from dask_cudf.core import DataFrame
  from dask_cudf.core import Series
  from functools import reduce
  import cugraph.dask.comms.comms
  from dask.delayed import delayed
  import cudf
label_desc: Use image node_id 13 for calling a global function with example usage: repartition(ddf, cumsum) and returns: ddf