//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        k: usize,
        a: [i64;n]
    }

    let mut a_sum = 0;
    for i in 0..n {
        a_sum += a[i];
    }

    let mut ans = 0;

    let mut divisors = enumerate_divisor(a_sum as usize);
    divisors.reverse();

    for &d in &divisors {
        let mut mod_d_vec = vec![];
        let mut mod_d_sum = 0;

        for &i in &a {
            // mod_dの部分を引くことでdの倍数にできる
            let mod_d = (i % d as i64) as usize;
            mod_d_sum += mod_d;
            mod_d_vec.push(mod_d);
        }

        // Σa % d = 0 なので、  Σ(a % d) = 0　=　X * d と表すことができる
        // 足して帳尻を合わせる場合、d - a % d を足せば良い。
        // 引く場合との変化量を見ると a % d - (d - a % d) = -d
        // よって、a%dが多いものから順に引く方式ではなく足す方式を採用することで総操作量は0になる。
        let powered_count = (mod_d_sum / d) as usize;

        mod_d_vec.sort();
        mod_d_vec.reverse();

        let mut operation = 0;
        for i in 0..mod_d_vec.len() {
            if i < powered_count {
                operation += d - mod_d_vec[i];
            } else {
                operation += mod_d_vec[i];
            }
        }

        operation /= 2;

        //println!("{} {:?} {}", mod_d_sum, mod_d_vec, operation);

        if operation <= k {
            println!("{}", d);
            break;
        }
    }
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet
// 約数の列挙
fn enumerate_divisor(n: usize) -> Vec<usize> {
    let mut i = 1;

    let mut divisors = vec![];

    while i * i <= n {
        if n % i == 0 {
            divisors.push(i);
            divisors.push(n / i);
        }
        i += 1;
    }

    divisors.sort();

    divisors
}


Measured memory_bytes: 8572