#include <iostream>
#include <unordered_map>
#include <functional>
#include <vector>
#include <iterator>
class Base
{
public:
static Base* build(std::istream& in)
{
int x;
in >> x;
return new Base(x);
}
Base(int x) {};
virtual void whoAmI()
{
std::cout << "Base\n";
}
};
class Derived: public Base
{
public:
static Derived* build(std::istream& in)
{
int x, y;
in >> x >> y;
return new Derived(x, y);
}
Derived(int x, int y) : Base(x) {};
virtual void whoAmI() override
{
std::cout << "Derived\n";
}
};
template <class OutputIterator>
OutputIterator loadData(std::istream& in, OutputIterator it)
{
using map_type = const std::unordered_map<int, std::function<Base*(std::istream&)>>;
static map_type builders = { {1, Base::build}, {2, Derived::build}, };
int x;
while(in >> x)
*it++ = builders.at(x)(in);
return it;
}
int main()
{
std::vector<Base*> pointers;
loadData(std::cin, std::back_inserter(pointers));
for(auto p: pointers)
p -> whoAmI();
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dW5vcmRlcmVkX21hcD4KI2luY2x1ZGUgPGZ1bmN0aW9uYWw+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxpdGVyYXRvcj4KCmNsYXNzIEJhc2UKewogICAgcHVibGljOgogICAgc3RhdGljIEJhc2UqIGJ1aWxkKHN0ZDo6aXN0cmVhbSYgaW4pCiAgICB7CiAgICAgICAgaW50IHg7CiAgICAgICAgaW4gPj4geDsKICAgICAgICByZXR1cm4gbmV3IEJhc2UoeCk7CiAgICB9CiAgICBCYXNlKGludCB4KSB7fTsKICAgIHZpcnR1YWwgdm9pZCB3aG9BbUkoKQogICAgewogICAgICAgIHN0ZDo6Y291dCA8PCAiQmFzZVxuIjsKICAgIH0KfTsKCmNsYXNzIERlcml2ZWQ6IHB1YmxpYyBCYXNlCnsKICAgIHB1YmxpYzoKICAgIHN0YXRpYyBEZXJpdmVkKiBidWlsZChzdGQ6OmlzdHJlYW0mIGluKQogICAgewogICAgICAgIGludCB4LCB5OwogICAgICAgIGluID4+IHggPj4geTsKICAgICAgICByZXR1cm4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