//! (c) WhiZTiM __ionogu(<_at_)>acm.org
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
struct Triples {
Triples() = default;
Triples(unsigned aa, unsigned bb, unsigned cc): a(aa), b(bb), c(cc) {}
unsigned a=0; unsigned b=0; unsigned c=0;
};
using vTriples = vector<Triples>;
vTriples triples(size_t lower, size_t max){
vTriples ans;
for(size_t x=lower; x<max; x++)
for(size_t y=x; y<max; y++)
for(size_t z=y; z<max; z++)
if(x*x + y*y == z*z)
ans.emplace_back(Triples(x, y, z));
return ans;
}
Triples triples_for(const vTriples& vt, size_t num){
auto rtn = find_if(vt.begin(), vt.end(),
[&num](const Triples& t){ return num == (t.a + t.b + t.c); });
return rtn != vt.end() ? *rtn : Triples();
}
int main() {
auto tp = triples(1, 1000);
auto t = triples_for(tp, 1000);
cout << t.a << ", " << t.b << ", " << t.c << '\n';
cout << "Product: " << t.a * t.b * t.c << '\n';
return 0;
}
Ly8hIChjKSBXaGlaVGlNIF9faW9ub2d1KDxfYXRfKT5hY20ub3JnCiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBUcmlwbGVzIHsgCglUcmlwbGVzKCkgPSBkZWZhdWx0OwoJVHJpcGxlcyh1bnNpZ25lZCBhYSwgdW5zaWduZWQgYmIsIHVuc2lnbmVkIGNjKTogYShhYSksIGIoYmIpLCBjKGNjKSB7fQoJdW5zaWduZWQgYT0wOyB1bnNpZ25lZCBiPTA7IHVuc2lnbmVkIGM9MDsKfTsKdXNpbmcgdlRyaXBsZXMgPSB2ZWN0b3I8VHJpcGxlcz47Cgp2VHJpcGxlcyB0cmlwbGVzKHNpemVfdCBsb3dlciwgc2l6ZV90IG1heCl7Cgl2VHJpcGxlcyBhbnM7Cglmb3Ioc2l6ZV90IHg9bG93ZXI7IHg8bWF4OyB4KyspCgkJZm9yKHNp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