#include <iostream>
#include <stdexcept>
#include <limits>
int multiply(int a, int b) {
if (a > 0 && b > 0 && a > (std::numeric_limits<int>::max() / b)) {
throw std::overflow_error("Overflow detected");
}
return a * b;
}
int main() {
try {
int x = 50000;
int y = 50000;
int result = multiply(x, y);
std::cout << "Result: " << result << std::endl;
} catch (const std::overflow_error& e) {
std::cout << "Error: " << e.what() << std::endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RkZXhjZXB0PgojaW5jbHVkZSA8bGltaXRzPgoKaW50IG11bHRpcGx5KGludCBhLCBpbnQgYikgewogICAgaWYgKGEgPiAwICYmIGIgPiAwICYmIGEgPiAoc3RkOjpudW1lcmljX2xpbWl0czxpbnQ+OjptYXgoKSAvIGIpKSB7CiAgICAgICAgdGhyb3cgc3RkOjpvdmVyZmxvd19lcnJvcigiT3ZlcmZsb3cgZGV0ZWN0ZWQiKTsKICAgIH0KICAgIHJldHVybiBhICogYjsKfQoKaW50IG1haW4oKSB7CiAgICB0cnkgewogICAgICAgIGludCB4ID0gNTAwMDA7CiAgICAgICAgaW50IHkgPSA1MDAwMDsKICAgICAgICBpbnQgcmVzdWx0ID0gbXVsdGlwbHkoeCwgeSk7CiAgICAgICAgc3RkOjpjb3V0IDw8ICJSZXN1bHQ6ICIgPDwgcmVzdWx0IDw8IHN0ZDo6ZW5kbDsKICAgIH0gY2F0Y2ggKGNvbnN0IHN0ZDo6b3ZlcmZsb3dfZXJyb3ImIGUpIHsKICAgICAgICBzdGQ6OmNvdXQgPDwgIkVycm9yOiAiIDw8IGUud2hhdCgpIDw8IHN0ZDo6ZW5kbDsKICAgIH0KCiAgICByZXR1cm4gMDsKfQo=