#include <iostream>
#include <algorithm>
#include <list>
int main()
{
std::list<int> nums = {1, 2, 3, 4, 5};
auto x = std::find(nums.begin(), nums.end(), 4);
auto &ref = *x;
std::cout << *x << std::endl;
nums.erase (std::find(nums.begin(), nums.end(), 3));
for (auto &i : nums)
std::cout << i << std::endl;
std::cout << *x << std::endl;
std::cout << ref << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgojaW5jbHVkZSA8bGlzdD4KCgppbnQgbWFpbigpCnsKICAgICAgICBzdGQ6Omxpc3Q8aW50PiBudW1zID0gezEsIDIsIDMsIDQsIDV9OwogICAgICAgIGF1dG8geCA9IHN0ZDo6ZmluZChudW1zLmJlZ2luKCksIG51bXMuZW5kKCksIDQpOwogICAgICAgIGF1dG8gJnJlZiA9ICp4OwoKICAgICAgICBzdGQ6OmNvdXQgPDwgKnggPDwgc3RkOjplbmRsOwoKICAgICAgICBudW1zLmVyYXNlIChzdGQ6OmZpbmQobnVtcy5iZWdpbigpLCBudW1zLmVuZCgpLCAzKSk7CiAgICAgICAgZm9yIChhdXRvICZpIDogbnVtcykKICAgICAgICAgICAgICAgIHN0ZDo6Y291dCA8PCBpIDw8IHN0ZDo6ZW5kbDsKCiAgICAgICAgc3RkOjpjb3V0IDw8ICp4IDw8IHN0ZDo6ZW5kbDsKICAgICAgICBzdGQ6OmNvdXQgPDwgcmVmIDw8IHN0ZDo6ZW5kbDsKfQo=