#include #include #include using lint = long long; template T gcd(T n, T m) { while (m != 0) { n %= m; std::swap(n, m); } return n; } void solve() { int n; std::cin >> n; std::vector xs(n); for (auto& x : xs) std::cin >> x; int i; for (i = n - 1; i >= 0; --i) { if (xs[i] != -1) break; } if (i < 0) { std::cout << -1 << std::endl; return; } for (auto& x : xs) { if (x == -1) x = xs[i]; } for (int k = 0; k < 20; ++k) { for (int b = n - 1; b >= 0; --b) { if ((b >> k) & 1) xs[b ^ (1 << k)] += xs[b]; } } lint g = 0; for (auto x : xs) g = gcd(g, x); std::cout << g * g << std::endl; } int main() { std::cin.tie(nullptr); std::cout.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }