#include <cstdio>
#include <utility>
using namespace std;
struct Heavy
{
Heavy() { printf("h "); }
Heavy(const Heavy&) { printf("H "); }
};
template<int N, class... Args> struct getter;
template<class A, class... Args> struct getter<0,A,Args...>
{
typedef A type;
static type&& get(A&& a, Args&&...) { printf("0 "); return std::forward<A>(a); }
};
template<int N, class A, class... Args> struct getter<N,A,Args...>
{
typedef getter<N-1,Args...> base;
typedef typename base::type type;
static type&& get(A&& a, Args&&... args)
{
printf("%d ", N);
return std::forward<type>(base::get(forward<Args>(args)...));
}
};
template<int N, class... Args>
typename getter<N,Args...>::type&&
get(Args&&... args)
{
printf("go ");
return std::forward<typename getter<N,Args...>::type>(getter<N,Args...>::get(forward<Args>(args)...));
}
int main()
{
get<4>(0,1,2,3,4, Heavy(), 6,7,8,9);
printf("\n");
get<5>(0,1,2,3,4, Heavy(), 6,7,8,9);
printf("\n");
get<9>(0,1,2,3,4, Heavy(), 6,7,8,9);
printf("\n");
}
I2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPHV0aWxpdHk+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IEhlYXZ5CnsKICAgIEhlYXZ5KCkgeyBwcmludGYoImggIik7IH0KICAgIEhlYXZ5KGNvbnN0IEhlYXZ5JikgeyBwcmludGYoIkggIik7IH0KfTsKCnRlbXBsYXRlPGludCBOLCBjbGFzcy4uLiBBcmdzPiBzdHJ1Y3QgZ2V0dGVyOwp0ZW1wbGF0ZTxjbGFzcyBBLCBjbGFzcy4uLiBBcmdzPiBzdHJ1Y3QgZ2V0dGVyPDAsQSxBcmdzLi4uPgp7CiAgICB0eXBlZGVmIEEgdHlwZTsKICAgIHN0YXRpYyB0eXBlJiYgZ2V0KEEmJiBhLCBBcmdzJiYuLi4pIHsgcHJpbnRmKCIwICIpOyByZXR1cm4gc3RkOjpmb3J3YXJkPEE+KGEpOyB9Cn07CnRlbXBsYXRlPGludCBOLCBjbGFzcyBBLCBjbGFzcy4uLiBBcmdzP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