#include <iterator>
template<typename T, typename Iterator>
Iterator finds(const T &value,
Iterator b,
Iterator e,
std::bidirectional_iterator_tag) {
while (b != e) {
if (*b == value)
return b;
else
b++;
}
return e;
}
template<typename T, typename Iterator>
Iterator finds(const T &value,
Iterator b,
Iterator e,
std::random_access_iterator_tag) {
Iterator l = b, r = e - 1, mid;
while (l < r) {
mid = (r - l) / 2 + l;
if (*mid < value)
l = mid + 1;
else
r = mid;
}
if (*l == value)
return l;
return e;
}
template<typename T, typename Iterator>
Iterator Find(const T &value, Iterator first, Iterator last) {
return finds(value, first, last,
typename std::iterator_traits<Iterator>::iterator_category());
}