use std::io::Read; fn gcd(a: i128, b: i128) -> i128 { if b == 0 { a } else { gcd(b, a % b) } } fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let n = n.next_power_of_two(); let m = n.trailing_zeros() as usize; let mut a = vec![0i128; n]; for (i, s) in it.enumerate() { let k: i128 = s.parse().unwrap(); if k >= 0 { a[i] = k; } } for i in 0..m { for j in 0..n { if (j >> i) & 1 == 1 { a[j ^ (1 << i)] += a[j]; } } } for i in 0..n { a[i] *= a[i]; } for i in 0..m { for j in 0..n { if (j >> i) & 1 == 1 { a[j ^ (1 << i)] -= a[j]; } } } let mut ans = 0; for a in a { ans = gcd(ans, a); } if ans == 0 { println!("-1"); } else { println!("{}", ans); } } fn main() { run(); }