#include #include //#include using std::vector; int conquer(vector &a, int b, int c, int left, int right) { int countB = 0; int countC = 0; for (int i = left; i < right + 1; i++) { if (a[i] == b) countB++; if (a[i] == c) countC++; } if (countB > (right - left + 1) / 2) return b; if (countC > (right - left + 1) / 2) return c; return -1; } int get_majority_element(vector &a, int left, int right) { if (left == right) return a[left]; int middle = (right - left) / 2; int b = get_majority_element(a, left, left + middle); int c = get_majority_element(a, left + middle + 1, right); int d = conquer(a, b, c, left, right); return d; } //TEST(MajorityElement, test1) { // vector a = { 1, 1 }; // ASSERT_EQ(get_majority_element(a, 0, a.size()-1), 1); //} int main() { int n; std::cin >> n; vector a(n); for (size_t i = 0; i < a.size(); ++i) { std::cin >> a[i]; } std::cout << (get_majority_element(a, 0, n - 1) != -1) << '\n'; }