#include <iostream>
using namespace std;
template <typename T>
class Interleave {
T a, b;
bool check = false;
public:
Interleave(T a, T b) {
this->a = a;
this->b = b;
}
T getValue() {
check = !check;
return check ? a : b;
}
};
int getNumber() {
static Interleave<int> numero(10, 20);
return numero.getValue();
}
int main() {
Interleave<int> numero(10, 20);
cout << numero.getValue() << endl;
cout << numero.getValue() << endl;
cout << numero.getValue() << endl;
Interleave<string> texto("aaa", "bbb");
cout << texto.getValue() << endl;
cout << texto.getValue() << endl;
cout << texto.getValue() << endl;
cout << getNumber() << endl;
cout << getNumber() << endl;
cout << getNumber() << endl;
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KICAgIHVzaW5nIG5hbWVzcGFjZSBzdGQ7CiAgICB0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4KICAgIGNsYXNzIEludGVybGVhdmUgewogICAgCVQgYSwgYjsKICAgIAlib29sIGNoZWNrID0gZmFsc2U7CiAgICAJcHVibGljOgogICAgCQlJbnRlcmxlYXZlKFQgYSwgVCBiKSB7CiAgICAJCQl0aGlzLT5hID0gYTsKICAgIAkJCXRoaXMtPmIgPSBiOwogICAgCQl9CiAgICAJCgkgICAgICAgIFQgZ2V0VmFsdWUoKSB7CiAgICAJICAgICAgICBjaGVjayA9ICFjaGVjazsKICAgICAgICAJICAgIHJldHVybiBjaGVjayA/IGEgOiBiOwogICAgICAgIAl9CiAgICB9OwogICAgCiAgICBpbnQgZ2V0TnVtYmVyKCkgewogICAgCXN0YXRpYyBJbnRlcmxlYXZlPGludD4gbnVtZXJvKDEwLCAyMCk7CiAgICAgICAgcmV0dXJuIG51bWVyby5nZXRWYWx1ZSgpOwogICAgfQogICAgCiAgICBpbnQgbWFpbigpIHsKICAgICAgICBJbnRlcmxlYXZlPGludD4gbnVtZXJvKDEwLCAyMCk7CiAgICAgICAgY291dCA8PCBudW1lcm8uZ2V0VmFsdWUoKSA8PCBlbmRsOwogICAgICAgIGNvdXQgPDwgbnVtZXJvLmdldFZhbHVlKCkgP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