#include <iostream>
auto create_counter()
{
return [counter = 0] () mutable { return ++counter; };
}
int main()
{
auto counter1 = create_counter();
auto counter2 = create_counter();
std::cout << counter1() << std::endl;
std::cout << counter1() << std::endl;
std::cout << counter2() << std::endl;
std::cout << counter2() << std::endl;
std::cout << counter1() << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgoKYXV0byBjcmVhdGVfY291bnRlcigpCnsKICAgIHJldHVybiBbY291bnRlciA9IDBdICgpIG11dGFibGUgeyByZXR1cm4gKytjb3VudGVyOyB9Owp9CgppbnQgbWFpbigpCnsKICAgYXV0byBjb3VudGVyMSA9IGNyZWF0ZV9jb3VudGVyKCk7CiAgIGF1dG8gY291bnRlcjIgPSBjcmVhdGVfY291bnRlcigpOwoKICAgc3RkOjpjb3V0IDw8IGNvdW50ZXIxKCkgPDwgc3RkOjplbmRsOwogICBzdGQ6OmNvdXQgPDwgY291bnRlcjEoKSA8PCBzdGQ6OmVuZGw7CgogICBzdGQ6OmNvdXQgPDwgY291bnRlcjIoKSA8PCBzdGQ6OmVuZGw7CiAgIHN0ZDo6Y291dCA8PCBjb3VudGVyMigpIDw8IHN0ZDo6ZW5kbDsKCiAgIHN0ZDo6Y291dCA8PCBjb3VudGVyMSgpIDw8IHN0ZDo6ZW5kbDsKfQo=