#include <iostream>
#include <vector>
using namespace std;
template<typename it>
struct range
{
it i_begin;
it i_end;
it begin() { return i_begin; }
it end() { return i_end; }
bool empty() { return i_begin == i_end; }
};
template<typename it>
range<it> make_range(it i_begin, it i_end)
{
return {i_begin, i_end};
}
template<typename t, typename range>
bool contains(const t& i_find, range&& list)
{
return list.begin() == list.end() ? false : (*list.begin() == i_find ? true : contains(i_find, make_range(std::next(list.begin()), list.end())));
}
int main() {
auto list = {1,2,3,4};
printf("contains 0: %i\n", contains(0, list) ? 1 : 0);
printf("contains 1: %i\n", contains(1, list) ? 1 : 0);
printf("contains 2: %i\n", contains(2, list) ? 1 : 0);
printf("contains 3: %i\n", contains(3, list) ? 1 : 0);
printf("contains 4: %i\n", contains(4, list) ? 1 : 0);
printf("contains 5: %i\n", contains(5, list) ? 1 : 0);
// your code goes here
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKdGVtcGxhdGU8dHlwZW5hbWUgaXQ+CnN0cnVjdCByYW5nZQp7CglpdCBpX2JlZ2luOwoJaXQgaV9lbmQ7CgkKCWl0IGJlZ2luKCkgeyByZXR1cm4gaV9iZWdpbjsgfQoJaXQgZW5kKCkgeyByZXR1cm4gaV9lbmQ7IH0KCglib29sIGVtcHR5KCkgeyByZXR1cm4gaV9iZWdpbiA9PSBpX2VuZDsgfQp9OwoKdGVtcGxhdGU8dHlwZW5hbWUgaXQ+CnJhbmdlPGl0PiBtYWtlX3JhbmdlKGl0IGlfYmVnaW4sIGl0IGlfZW5kKQp7CglyZXR1cm4ge2lfYmVnaW4sIGlfZW5kfTsKfQoKdGVtcGxhdGU8dHlwZW5hbWUgdCwgdHlwZW5hbWUgcmFuZ2U+CmJvb2wgY29udGFpbnMoY29uc3QgdCYgaV9maW5kLCByYW5nZSYmIGxpc3QpCnsKICByZXR1cm4gbGlzdC5iZWdpbigpID09IGxpc3QuZW5kKCkgPyBmY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