code: def spread(nodes, n):
      
      target = []
  
      while len(target) < n and nodes:
          for ip, node_group in list(nodes.items()):
              if not node_group:
                  nodes.pop(ip)
                  continue
              target.append(node_group.pop(0))
              if len(target) >= n:
                  break
      return target
docs: Distrubute master instances in different nodes
  
      {
          "192.168.0.1": [node1, node2],
          "192.168.0.2": [node3, node4],
          "192.168.0.3": [node5, node6]
      } => [node1, node3, node5]