#include <iostream>
#include <algorithm>
template<class T>
const T& Limit(const T& Min, const T& Max, const T& Value){
const T& A = Min < Max ? Min : Max;//min
const T& B = Min < Max ? Max : Min;//max
const T& C = std::max(Value, A);
return std::min(C, B);
}
int main(){
int Max = 100;
int Min = -100;
int Mid = 0;
std::cout << Limit(Max, Min, 101) << std::endl;
std::cout << Limit(Max, Mid, 101) << std::endl;
std::cout << Limit(Max, Min, 0) << std::endl;
std::cout << Limit(Max, Mid, 50) << std::endl;
std::cout << Limit(Max, Min, -101) << std::endl;
std::cout << Limit(Max, Mid, -1) << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdGVtcGxhdGU8Y2xhc3MgVD4KY29uc3QgVCYgTGltaXQoY29uc3QgVCYgTWluLCBjb25zdCBUJiBNYXgsIGNvbnN0IFQmIFZhbHVlKXsKCWNvbnN0IFQmIEEgPSBNaW4gPCBNYXggPyBNaW4gOiBNYXg7Ly9taW4KCWNvbnN0IFQmIEIgPSBNaW4gPCBNYXggPyBNYXggOiBNaW47Ly9tYXgKCgljb25zdCBUJiBDID0gc3RkOjptYXgoVmFsdWUsIEEpOwoJcmV0dXJuIHN0ZDo6bWluKEMsIEIpOwp9CgppbnQgbWFpbigpewoKCWludCBNYXggPSAxMDA7CglpbnQgTWluID0gLTEwMDsKCWludCBNaWQgPSAwOwoKCXN0ZDo6Y291dCA8PCBMaW1pdChNYXgsIE1pbiwgMTAxKSA8PCBzdGQ6OmVuZGw7CglzdGQ6OmNvdXQgPDwgTGltaXQoTWF4LCBNaWQsIDEwMSkgPDwgc3RkOjplbmRsOwoJc3RkOjpjb3V0IDw8IExpbWl0KE1heCwgTWluLCAwKSA8PCBzdGQ6OmVuZGw7CglzdGQ6OmNvdXQgPDwgTGltaXQoTWF4LCBNaWQsIDUwKSA8PCBzdGQ6OmVuZGw7CglzdGQ6OmNvdXQgPDwgTGltaXQoTWF4LCBNaW4sIC0xMDEpIDw8IHN0ZDo6ZW5kbDsKCXN0ZDo6Y291dCA8PCBMaW1pdChNYXgsIE1pZCwgLTEpIDw8IHN0ZDo6ZW5kbDsKCXJldHVybiAwOwp9