#pragma once
#include <map>
#include <optional>

namespace red_black {
namespace map {
using Key = int;
using Value = int;

struct Tree {
    std::map<Key, Value> m;

    void insert(Key x, Value v) {
        //m.insert({x, v});
        m[x] = v;
    }

    std::optional<Value> find(Key x) {
        auto it = m.find(x);
        if (it == m.end())
            //return std::nullopt;
            return {};
        else
            return it->second; // (*it).second
    }

    std::optional<Value> remove(Key x) {
        auto it = m.find(x);
        if (it == m.end())
            return {};
        else {
            Value v = it->second;
            m.erase(it);
            return v;
        }
    }

    size_t size() const {
        return m.size();
    }
};
}
}
