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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize,
        v: [usize; n]
    }
    let mut divs = divisors(v.iter().cloned().sum());
    divs.sort_by(|x, y| y.cmp(&x));
    for &d in &divs {
        let mut rs: Vec<usize> = v.iter().map(|&x| x % d).collect();
        rs.sort();
        let mut ac = vec![0; n + 1];
        for i in 0..n {
            ac[i + 1] = ac[i] + rs[i];
        }
        let mut l = 0;
        let mut r = n + 1;
        while l + 1 < r {
            let m = (l + r) / 2;
            if ac[m] > k {
                r = m;
            } else {
                l = m;
            }
        }
        if (n - l) * d + ac[l] - ac[n] <= k {
            println!("{}", d);
            return;
        }
    }
}

fn factor(mut n: usize) -> Vec<(usize, usize)> {
    let mut ret = vec![];
    let mut p = 0;
    while n % 2 == 0 {
        p += 1;
        n /= 2;
    }
    if p != 0 {
        ret.push((2, p));
    }
    let mut r = 3;
    while r * r <= n {
        p = 0;
        while n % r == 0 {
            p += 1;
            n /= r;
        }
        if p != 0 {
            ret.push((r, p));
        }
        r += 2;
    }
    if n != 1 {
        ret.push((n, 1));
    }
    ret
}

fn divisors(n: usize) -> Vec<usize> {
    let mut ret = vec![];
    let fac = factor(n);
    let m = fac.len();
    let mut st = vec![0; m];
    while st[m - 1] <= fac[m - 1].1 {
        let mut d = 1;
        for i in 0..m {
            d *= fac[i].0.pow(st[i] as u32);
        }
        ret.push(d);
        st[0] += 1;
        let mut j = 0;
        while j < m - 1 && st[j] > fac[j].1 {
            st[j] = 0;
            st[j + 1] += 1;
            j += 1;
        }
    }
    ret
}


Measured memory_bytes: 4352