#include <iostream>
#include <vector>
#include <unordered_map>
#include <algorithm>
#include <tuple>

using namespace std;

class State {
public:
    vector<vector<int>> stacks;
    int w, h, size;
    vector<int> heights;
    pair<int, int> req;

    State();
    State(const vector<vector<int>>& _stacks, pair<int, int> _req);
    State copy() const;
    bool operator==(const State& other) const;
    struct HashFunction;
    bool add(int i, int v);
    void pop(int i);
    void sort_stacks();
    void print() const;
};