#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <list>

template <typename Value, typename It>
It find(const Value& a, It b, It c, std::random_access_iterator_tag) {
It res = c;
c--;
while (b < c) {
It mid = b + (c - b) / 2;

if (*mid < a) {
b = mid + 1;
} else {
c = mid;
}
}
if (*b == a) {
res = b;
}
return res;
}

template <typename Value, typename It>
It find(const Value& a, It b, It c, std::bidirectional_iterator_tag) {
while (b != c) {
if (*b == a) break;
b++;
}
return b;
}

template <typename Value, typename It>
It find(const Value& a, It b, It c, std::forward_iterator_tag) {
while (b != c) {
if (*b == a) break;
b++;
}
return b;
}

template <typename Value, typename It>
It Find(const Value& a, It b, It c) {
return find(a, b, c,
typename std::iterator_traits<It>::iterator_category());
}