#include <set>
#include <algorithm>
#include <iostream>
class CountIt {
public:
CountIt() : storage(0), counter(0) {}
CountIt& operator++()
{
++counter;
return *this;
}
CountIt operator++(int)
{
CountIt oldValue = *this;
return ++(*this);
}
int& operator*() { return storage;}
int storage, counter;
};
int main()
{
std::set<int> s1 { 1,2,3,4 };
std::set<int> s2 { 3,4,5,6 };
CountIt const & c = std::set_intersection(
s1.begin(), s1.end(), s2.begin(), s2.end(),
CountIt()
);
std::cout << c.counter;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgQ291bnRJdCB7CglwdWJsaWM6CglDb3VudEl0KCkgOiBzdG9yYWdlKDApLCBjb3VudGVyKDApIHt9CglDb3VudEl0JiBvcGVyYXRvcisrKCkKCXsKCQkrK2NvdW50ZXI7CgkJcmV0dXJuICp0aGlzOwoJfQogICAgQ291bnRJdCBvcGVyYXRvcisrKGludCkKCXsKCQlDb3VudEl0IG9sZFZhbHVlID0gKnRoaXM7CgkJcmV0dXJuICsrKCp0aGlzKTsKCX0KCWludCYgb3BlcmF0b3IqKCkgeyByZXR1cm4gc3RvcmFnZTt9CiAgICBpbnQgc3RvcmFnZSwgY291bnRlcjsKfTsKCmludCBtYWluKCkKewogICAgc3RkOjpzZXQ8aW50PiBzMSB7IDEsMiwzLDQgfTsKICAgIHN0ZDo6c2V0PGludD4gczIgeyAzLDQsNSw2IH07CgogICBDb3VudEl0IGNvbnN0ICYgYyA9IHN0ZDo6c2V0X2ludGVyc2VjdGlvbigKICAgICAgICBzMS5iZWdpbigpLCBzMS5lbmQoKSwgczIuYmVnaW4oKSwgczIuZW5kKCksCiAgICAgICAgQ291bnRJdCgpCiAgICApOwoKICAgIHN0ZDo6Y291dCA8PCBjLmNvdW50ZXI7Cn0=