#include #define loop(n) for (int ngtkana_is_genius = 0; ngtkana_is_genius < int(n); ngtkana_is_genius++) #define rep(i, begin, end) for(int i = int(begin); i < int(end); i++) #define all(v) v.begin(), v.end() #define rand(l, r) std::uniform_int_distribution<>(l, r)(mt) using lint = long long; auto mt = std::mt19937_64(std::random_device{}()); auto cmn = [](auto& a, auto b){if (a > b) {a = b; return true;} return false;}; auto cmx = [](auto& a, auto b){if (a < b) {a = b; return true;} return false;}; void debug_impl() { std::cerr << std::endl; } template void debug_impl(Head head, Tail... tail){ std::cerr << " " << head; debug_impl(tail...); } #ifdef STOPIT #define debug(...) 0 #else #define debug(...)\ do {\ std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\ debug_impl(__VA_ARGS__);\ std::cerr << std::noboolalpha;\ } while (false) #endif template < typename Container, typename Value = typename Container::value_type, std::enable_if_t::value, std::nullptr_t> = nullptr> std::istream& operator>> (std::istream& is, Container& v) { for (auto & x : v) { is >> x; } return is; } template < typename Container, typename Value = typename Container::value_type, std::enable_if_t::value, std::nullptr_t> = nullptr > std::ostream& operator<< (std::ostream& os, Container const& v) { os << "{"; for (auto it = v.begin(); it != v.end(); it++) {os << (it != v.begin() ? "," : "") << *it;} return os << "}"; } template < template < typename ... > class Tuple, typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::istream& tuple_input_impl(std::istream& os, Tuple& tuple, std::integer_sequence) { (void)std::initializer_list{((void)(os >> std::get< Inds >(tuple)), 0)...}; return os; } template < template < typename ... > class Tuple, typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::istream& operator>> (std::istream& os, Tuple& tuple) { return tuple_input_impl(os, tuple, std::index_sequence_for()); } template < template < typename ... > class Tuple, typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::ostream& tuple_output_impl(std::ostream& os, const Tuple& tuple, std::integer_sequence) { os << "("; (void)std::initializer_list{((void)(os << (Inds > 0 ? "," : "") << std::get< Inds >(tuple)), 0)...}; return os << ")"; } template < template < typename ... > class Tuple, typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value > std::ostream& operator<< (std::ostream& os, const Tuple& tuple) { return tuple_output_impl(os, tuple, std::index_sequence_for()); } template < template < typename ... > class Container, typename Value > auto runlength(Container< Value > const& v) { auto n = (int)v.size(); if (n == 0) { return Container< std::pair< Value, int > >{}; } auto pos = Container< int >{}; for (auto i = 1; i < n; i++) { if (v.at(i - 1) != v.at(i)) { pos.emplace_back(i); } } pos.emplace_back(n); auto m = (int)pos.size(); auto len = Container< int >(m); std::adjacent_difference(pos.begin(), pos.end(), len.begin()); auto ret = Container< std::pair< Value, int > >(m); for (auto i = 0; i != m; i++) { ret.at(i) = {v.at(pos.at(i) - 1), len.at(i)}; } return ret; } int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); int n; std::cin >> n; std::vector< int > a(n); std::cin >> a; auto rle = runlength(a); // debug(rle); int x = 0, y = 0; for (auto pair : rle) { int z = pair.second; int new_x = std::max(x, y); int new_y = x + z; x = new_x; y = new_y; } int ans = std::max(x, y); std::cout << ans << std::endl; return 0; }