human
Solve in Python:
You have an infinite number of stacks arranged in a row and numbered (left to right) from 0, each of the stacks has the same maximum capacity.
Implement the DinnerPlates class:

DinnerPlates(int capacity) Initializes the object with the maximum capacity of the stacks.
void push(int val) Pushes the given positive integer val into the leftmost stack with size less than capacity.
int pop() Returns the value at the top of the rightmost non-empty stack and removes it from that stack, and returns -1 if all stacks are empty.
int popAtStack(int index) Returns the value at the top of the stack with the given index and removes it from that stack, and returns -1 if the stack with that given index is empty.

Example:
Input: 
["DinnerPlates","push","push","push","push","push","popAtStack","push","push","popAtStack","popAtStack","pop","pop","pop","pop","pop"]
[[2],[1],[2],[3],[4],[5],[0],[20],[21],[0],[2],[],[],[],[],[]]
Output: 
[null,null,null,null,null,null,2,null,null,20,21,5,4,3,1,-1]

Explanation: 
DinnerPlates D = DinnerPlates(2).
 // Initialize with capacity = 2
D.push(1);
D.push(2);
D.push(3);
D.push(4);
D.push(5).
        // The stacks are now:  2  4
                                           1  3  5
                                           ﹈ ﹈ ﹈
D.popAtStack(0).
  // Returns 2.  The stacks are now:     4
                                                       1  3  5
                                                       ﹈ ﹈ ﹈
D.push(20).
       // The stacks are now: 20  4
                                           1  3  5
                                           ﹈ ﹈ ﹈
D.push(21).
       // The stacks are now: 20  4 21
                                           1  3  5
                                           ﹈ ﹈ ﹈
D.popAtStack(0).
  // Returns 20.  The stacks are now:     4 21
                                                        1  3  5
                                                        ﹈ ﹈ ﹈
D.popAtStack(2).
  // Returns 21.  The stacks are now:     4
                                             ...
 ... Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

class DinnerPlates:

    def __init__(self, capacity: int):
        self.max = capacity
        self.top = 0
        self.stack = collections.defaultdict(list)
        self.stack[self.top] = [0, []]
        self.h = []; 
        heapq.heappush(self.h, 0)
        
    def push(self, val: int) -> None:
        
        ptr = heapq.heappop(self.h)
        self.stack[ptr][1].append(val)
        self.stack[ptr][0] += 1
        if self.stack[ptr][0]<self.max: heapq.heappush(self.h, ptr)
        elif ptr==self.top: 
            self.top += 1
            self.stack[self.top] = [0, []]
            heapq.heappush(self.h, self.top)

        
    def popAtStack(self, index: int) -> int:

        if not index in self.stack or not self.stack[index][0]: return -1
        if self.stack[index][0]==self.max:
            heapq.heappush(self.h, index)
        self.stack[index][0] -= 1
        return self.stack[index][1].pop() 
        
    def pop(self) -> int:
        while self.top  and not self.stack[self.top][0]:
            self.top -= 1
        return self.popAtStack(self.top)

        
        

# Your DinnerPlates object will be instantiated and called as such:
# obj = DinnerPlates(capacity)
# obj.push(val)
# param_2 = obj.pop()
# param_3 = obj.popAtStack(index)