#include <iostream>
#include <algorithm>
template <class T>
struct S
{
T I;
S()
{
static int i;
int sign = i % 2 ? 1 : -1;
I = ++i * sign;
}
bool operator < (const S& rhs) const
{
return I < rhs.I;
}
};
namespace std {
template <class T>
inline void swap(S<T>& lhs, S<T>& rhs)
{
std::cout << "called" << std::endl;
int tmp = lhs.I;
lhs.I = rhs.I;
rhs.I = tmp;
}
}
int main()
{
S<int> s[10];
for (unsigned i = 0; i < sizeof(s) / sizeof(s[0]); ++i)
{
std::cout << s[i].I << ' ';
}
std::cout << std::endl;
std::sort(s, s + sizeof(s) / sizeof(s[0]));
for (unsigned i = 0; i < sizeof(s) / sizeof(s[0]); ++i)
{
std::cout << s[i].I << ' ';
}
std::cout << std::endl;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdGVtcGxhdGUgPGNsYXNzIFQ+CnN0cnVjdCBTCnsgICAKICAgIFQgSTsKICAgIFMoKQogICAgeyAgIAogICAgICAgIHN0YXRpYyBpbnQgaTsKICAgICAgICBpbnQgc2lnbiA9IGkgJSAyID8gMSA6IC0xOwogICAgICAgIEkgPSArK2kgKiBzaWduOwogICAgfQoKICAgIGJvb2wgb3BlcmF0b3IgPCAoY29uc3QgUyYgcmhzKSBjb25zdAogICAgeyAgIAogICAgICAgIHJldHVybiBJIDwgcmhzLkk7CiAgICB9Cn07CgpuYW1lc3BhY2Ugc3RkIHsKICAgIHRlbXBsYXRlIDxjbGFzcyBUPgogICAgaW5saW5lIHZvaWQgc3dhcChTPFQ+JiBsaHMsIFM8VD4mIHJocykKICAgIHsgICAKICAgICAgICBzdGQ6OmNvdXQgPDwgImNhbGxlZCIgPDwgc3RkOjplbmRsOwogICAgICAgIGludCB0bXAgPSBsaHMuSTsKICAgICAgICBsaHMuSSA9IHJocy5JOwogICAgICAgIHJocy5JID0gdG1wOwogICAgfQp9CgppbnQgbWFpbigpCnsgICAKICAgIFM8aW50PiBzWzEwXTsKICAgIGZvciAodW5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