#include <set>
#include <iostream>
class Foo {
public:
Foo(int v1, int v2) : val1(v1), val2(v2) {};
bool operator<(const Foo &foo) const { return val2 < foo.val2; }
int val1;
int val2;
};
int main()
{
std::multiset<Foo> ms;
ms.insert(Foo(1, 6));
ms.insert(Foo(1, 5));
ms.insert(Foo(3, 4));
ms.insert(Foo(2, 4));
for (auto const &foo : ms)
std::cout << foo.val1 << " " << foo.val2 << std::endl;
std::cout << std::endl;
std::set<Foo> s;
s.insert(Foo(1, 6));
s.insert(Foo(1, 5));
s.insert(Foo(3, 4));
s.insert(Foo(2, 4));
for (auto const &foo : s)
std::cout << foo.val1 << " " << foo.val2 << std::endl;
return 0;
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKY2xhc3MgRm9vIHsKcHVibGljOgogICAgRm9vKGludCB2MSwgaW50IHYyKSA6IHZhbDEodjEpLCB2YWwyKHYyKSB7fTsKICAgIGJvb2wgb3BlcmF0b3I8KGNvbnN0IEZvbyAmZm9vKSBjb25zdCB7IHJldHVybiB2YWwyIDwgZm9vLnZhbDI7IH0KICAgIGludCB2YWwxOwogICAgaW50IHZhbDI7Cn07CgppbnQgbWFpbigpCnsKICAgIHN0ZDo6bXVsdGlzZXQ8Rm9vPiBtczsKICAgIG1zLmluc2VydChGb28oMSwgNikpOwogICAgbXMuaW5zZXJ0KEZvbygxLCA1KSk7CiAgICBtcy5pbnNlcnQoRm9vKDMsIDQpKTsKICAgIG1zLmluc2VydChGb28oMiwgNCkpOwoKICAgIGZvciAoYXV0byBjb25zdCAmZm9vIDogbXMpCiAgICAgICAgc3RkOjpjb3V0IDw8IGZvby52YWwxIDw8ICIgIiA8PCBmb28udmFsMiA8PCBzdGQ6OmVuZGw7CgogICAgc3RkOjpjb3V0IDw8IHN0ZDo6ZW5kbDsKICAgIHN0ZDo6c2V0PEZvbz4gczsKICAgIHMuaW5zZXJ0KEZvbygxLCA2KSk7CiAgICBzLmluc2VydChGb28oMSwgNSkpOwogICAgcy5pbnNlcnQoRm9vKDMsIDQpKTsKICAgIHMuaW5zZXJ0KEZvbygyLCA0KSk7CgogICAgZm9yIChhdXRvIGNvbnN0ICZmb28gOiBzKQogICAgICAgIHN0ZDo6Y291dCA8PCBmb28udmFsMSA8PCAiICIgPDwgZm9vLnZhbDIgPDwgc3RkOjplbmRsOwoKICAgIHJldHVybiAwOwp9