#include <iostream>
#include <vector>
using namespace std;
template<class T>
class ReversedProxy {
public:
using iterator = typename T::reverse_iterator;
iterator begin() { return begin_; }
iterator end() { return end_; }
ReversedProxy(const iterator& begin, const iterator& end) : begin_(begin), end_(end) {}
private:
iterator begin_;
iterator end_;
};
template<class T>
ReversedProxy<T> reversed(T& obj) {
return ReversedProxy<T>(obj.rbegin(), obj.rend());
}
int main() {
vector<int> v = {1, 2, 3, 4};
for (int x : reversed(v)) {
cout << x << ' ';
} cout << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnRlbXBsYXRlPGNsYXNzIFQ+CmNsYXNzIFJldmVyc2VkUHJveHkgewpwdWJsaWM6CiAgICB1c2luZyBpdGVyYXRvciA9IHR5cGVuYW1lIFQ6OnJldmVyc2VfaXRlcmF0b3I7CiAgICBpdGVyYXRvciBiZWdpbigpIHsgcmV0dXJuIGJlZ2luXzsgfQogICAgaXRlcmF0b3IgZW5kKCkgeyByZXR1cm4gZW5kXzsgfQogICAgUmV2ZXJzZWRQcm94eShjb25zdCBpdGVyYXRvciYgYmVnaW4sIGNvbnN0IGl0ZXJhdG9yJiBlbmQpIDogYmVnaW5fKGJlZ2luKSwgZW5kXyhlbmQpIHt9CnByaXZhdGU6CiAgICBpdGVyYXRvciBiZWdpbl87CiAgICBpdGVyYXRvciBlbmRfOwp9Owp0ZW1wbGF0ZTxjbGFzcyBUPgpSZXZlcnNlZFByb3h5PFQ+IHJldmVyc2VkKFQmIG9iaikgewogICAgcmV0dXJuIFJldmVyc2VkUHJveHk8VD4ob2JqLnJiZWdpbigpLCBvYmoucmVuZCgpKTsKfQoKaW50IG1haW4oKSB7CiAgICB2ZWN0b3I8aW50PiB2ID0gezEsIDIsIDMsIDR9OwogICAgZm9yIChpbnQgeCA6IHJldmVyc2VkKHYpKSB7CiAgICAgICAgY291dCA8PCB4IDw8ICcgJzsKICAgIH0gY291dCA8PCBlbmRsOwogICAgcmV0dXJuIDA7Cn0KCgoK