#![allow(unused_imports, non_snake_case)] #![allow(dead_code)] use crate::prime_number::divisors; use crate::scanner::Scanner; fn main() { let mut scan = Scanner::new(); let n = scan.read::(); let a = scan.readn::(n); let s = a.sum(); let d = divisors(s); let mut ret = 0; 'outer: for &t in &d { let mut tmp = 0; let mut cnt = 0; for i in 0..n { tmp += a[i]; if t == tmp { tmp = 0; cnt += 1; } else if tmp > t { continue 'outer; } } chmax!(ret, cnt); } println!("{}", ret); } pub mod arraylist { use crate::{ext::range::IntRangeBounds, independent::integer::Int}; use std::fmt::Formatter; use std::iter::FromIterator; use std::ops::{Index, IndexMut, RangeBounds}; use std::slice::Iter; #[derive(Clone, PartialEq, Eq)] pub struct List { pub vec: Vec, } impl List { #[inline] pub fn new() -> List { List { vec: vec![] } } #[inline] pub fn init(init: T, n: i32) -> List where T: Clone, { List { vec: vec![init; n as usize], } } #[inline] pub fn from_vec(vec: Vec) -> List { List { vec } } #[inline] pub fn ilen(&self) -> i32 { self.vec.len() as i32 } #[inline] pub fn iter(&self) -> Iter<'_, T> { self.vec.iter() } #[inline] pub fn push(&mut self, item: T) { self.vec.push(item); } #[inline] pub fn sort(&mut self) where T: Ord, { self.vec.sort(); } #[inline] pub fn reverse(&mut self) { self.vec.reverse(); } #[inline] pub fn sort_by(&mut self, compare: F) where F: FnMut(&T, &T) -> std::cmp::Ordering, { self.vec.sort_by(compare) } #[inline] pub fn sort_by_key(&mut self, compare: F) where F: FnMut(&T) -> K, K: Ord, { self.vec.sort_by_key(compare) } #[inline] pub fn first(&self) -> Option<&T> { self.vec.first() } #[inline] pub fn last(&self) -> Option<&T> { self.vec.last() } #[inline] pub fn pop(&mut self) -> Option { self.vec.pop() } #[inline] pub fn swap(&mut self, i: i32, j: i32) { self.vec.swap(i as usize, j as usize); } #[inline] pub fn append(&mut self, mut other: Self) { self.vec.append(&mut other.vec); } #[inline] pub fn extend(&mut self, other: impl Iterator) { self.vec.extend(other); } #[inline] pub fn mirror(&self) -> std::iter::Cloned> where T: Clone, { self.iter().cloned() } #[inline] pub fn join(&self, sep: &str) -> String where T: std::fmt::Display, { self.iter() .map(|x| format!("{}", x)) .collect::>() .join(sep) } #[inline] pub fn map(&self, f: F) -> List where T: Clone, F: FnMut(T) -> B, { self.mirror().map(f).collect() } #[inline] pub fn filter

(&self, predicate: P) -> List where T: Clone, P: FnMut(&T) -> bool, { self.mirror().filter(predicate).collect() } #[inline] pub fn filter_map(&self, f: F) -> List where T: Clone, F: FnMut(T) -> Option, { self.mirror().filter_map(f).collect() } #[doc = " |acc, x| -> acc"] #[inline] pub fn fold(&self, init: B, f: F) -> B where T: Clone, F: FnMut(B, T) -> B, { self.mirror().fold(init, f) } #[inline] pub fn any

(&self, predicate: P) -> bool where P: FnMut(&T) -> bool, { self.iter().any(predicate) } #[inline] pub fn all

(&self, predicate: P) -> bool where P: FnMut(&T) -> bool, { self.iter().all(predicate) } #[inline] pub fn sum(&self) -> T where T: Int, { self.iter().cloned().fold(T::zero(), |acc, x| acc + x) } #[inline] pub fn enumerate(&self) -> List<(i32, T)> where T: Clone, { self.mirror() .enumerate() .map(|p| (p.0 as i32, p.1)) .collect() } #[inline] pub fn find

(&self, mut predicate: P) -> Option<&T> where P: FnMut(&T) -> bool, { self.iter().find(|x| predicate(*x)) } #[inline] pub fn index_of

(&self, mut predicate: P) -> Option where P: FnMut(&T) -> bool, { self.iter() .enumerate() .find(|&(_i, x)| predicate(x)) .map(|p| p.0 as i32) } #[inline] pub fn to>(&self) -> B where T: Clone, { self.mirror().collect() } #[inline] pub fn min(&self) -> Option<&T> where T: Ord, { self.iter().min() } #[inline] pub fn max(&self) -> Option<&T> where T: Ord, { self.iter().max() } #[inline] pub fn argmin(&self) -> Option where T: Ord, { let item = self.iter().min()?; self.iter() .enumerate() .find(|p| p.1 == item) .map(|p| p.0 as i32) } #[inline] pub fn argmax(&self) -> Option where T: Ord, { let item = self.iter().max()?; self.iter() .enumerate() .find(|p| p.1 == item) .map(|p| p.0 as i32) } #[inline] pub fn part(&self, range: U) -> List where T: Clone, U: RangeBounds, { List::from_vec( self.vec[range.lower_bound(0) as usize..range.upper_bound(self.ilen()) as usize] .to_vec(), ) } #[inline] pub fn first_exn(&self) -> &T { self.first().unwrap() } #[inline] pub fn last_exn(&self) -> &T { self.last().unwrap() } #[inline] pub fn pop_exn(&mut self) -> T { self.pop().unwrap() } #[inline] pub fn min_exn(&self) -> &T where T: Ord, { self.min().unwrap() } #[inline] pub fn max_exn(&self) -> &T where T: Ord, { self.max().unwrap() } #[inline] pub fn argmin_exn(&self) -> i32 where T: Ord, { self.argmin().unwrap() } #[inline] pub fn argmax_exn(&self) -> i32 where T: Ord, { self.argmax().unwrap() } #[inline] pub fn find_exn

(&self, predicate: P) -> &T where P: FnMut(&T) -> bool, { self.find(predicate).unwrap() } #[inline] pub fn index_of_exn

(&self, predicate: P) -> i32 where P: FnMut(&T) -> bool, { self.index_of(predicate).unwrap() } } impl Index for List { type Output = T; #[inline] fn index(&self, index: i32) -> &Self::Output { if cfg!(debug_assertions) { self.vec.index(index as usize) } else { unsafe { self.vec.get_unchecked(index as usize) } } } } impl IndexMut for List { #[inline] fn index_mut(&mut self, index: i32) -> &mut Self::Output { if cfg!(debug_assertions) { self.vec.index_mut(index as usize) } else { unsafe { self.vec.get_unchecked_mut(index as usize) } } } } impl FromIterator for List { fn from_iter>(iter: U) -> Self { let mut vec = vec![]; for i in iter { vec.push(i); } List { vec } } } impl IntoIterator for List { type Item = T; type IntoIter = std::vec::IntoIter; fn into_iter(self) -> std::vec::IntoIter { self.vec.into_iter() } } impl<'a, T> IntoIterator for &'a List { type Item = &'a T; type IntoIter = Iter<'a, T>; fn into_iter(self) -> Iter<'a, T> { self.vec.iter() } } impl std::fmt::Display for List { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!( f, "{}", self.iter() .map(|x| format!("{}", x)) .collect::>() .join(" ") ) } } impl std::fmt::Debug for List { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!( f, "[{}]", self.iter() .map(|x| format!("{:?}", x)) .collect::>() .join(", ") ) } } impl From> for List { fn from(vec: Vec) -> Self { Self::from_vec(vec) } } impl From<&[T]> for List { fn from(slice: &[T]) -> Self { slice.iter().cloned().collect() } } #[macro_export] macro_rules ! list { ( ) => { $ crate :: arraylist :: List :: new ( ) } ; ( $ ( $ v : expr ) ,+ $ ( , ) ? ) => { $ crate :: arraylist :: List :: from_vec ( [ $ ( $ v ) ,+ ] . to_vec ( ) ) } ; ( $ v : expr ; $ a : expr ) => { $ crate :: arraylist :: List :: init ( $ v , $ a ) } ; ( $ v : expr ; $ a : expr ; $ ( $ rest : expr ) ;+ ) => { $ crate :: arraylist :: List :: init ( list ! ( $ v ; $ ( $ rest ) ;+ ) , $ a ) } ; } } pub mod independent { pub mod integer { pub trait Int: std::ops::Add + std::ops::Sub + std::ops::Mul + std::ops::Div + std::ops::Rem + std::ops::AddAssign + std::ops::SubAssign + std::ops::MulAssign + std::ops::DivAssign + std::hash::Hash + PartialEq + Eq + PartialOrd + Ord + Copy { fn to_u8(&self) -> u8; fn to_u16(&self) -> u16; fn to_u32(&self) -> u32; fn to_u64(&self) -> u64; fn to_u128(&self) -> u128; fn to_i8(&self) -> i8; fn to_i16(&self) -> i16; fn to_i32(&self) -> i32; fn to_i64(&self) -> i64; fn to_i128(&self) -> i128; fn to_usize(&self) -> usize; fn to_isize(&self) -> isize; fn from_u8(x: u8) -> Self; fn from_u16(x: u16) -> Self; fn from_u32(x: u32) -> Self; fn from_u64(x: u64) -> Self; fn from_u128(x: u128) -> Self; fn from_i8(x: i8) -> Self; fn from_i16(x: i16) -> Self; fn from_i32(x: i32) -> Self; fn from_i64(x: i64) -> Self; fn from_i128(x: i128) -> Self; fn from_usize(x: usize) -> Self; fn from_isize(x: isize) -> Self; fn zero() -> Self; fn one() -> Self; fn next(&self) -> Self { *self + Self::one() } } macro_rules ! impl_integer_functions { ( $ selftpe : ident , $ ( $ tofn : ident , $ fromfn : ident , $ tpe : ident ) ,* ) => { $ ( fn $ tofn ( & self ) -> $ tpe { * self as $ tpe } fn $ fromfn ( x : $ tpe ) -> Self { x as $ selftpe } ) * } ; } macro_rules ! impl_integer { ( $ ( $ tpe : ident ) ,* ) => { $ ( impl Int for $ tpe { impl_integer_functions ! ( $ tpe , to_u8 , from_u8 , u8 , to_u16 , from_u16 , u16 , to_u32 , from_u32 , u32 , to_u64 , from_u64 , u64 , to_u128 , from_u128 , u128 , to_i8 , from_i8 , i8 , to_i16 , from_i16 , i16 , to_i32 , from_i32 , i32 , to_i64 , from_i64 , i64 , to_i128 , from_i128 , i128 , to_usize , from_usize , usize , to_isize , from_isize , isize ) ; fn zero ( ) -> Self { 0 } fn one ( ) -> Self { 1 } } ) * } ; } impl_integer!(u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, usize, isize); } } pub mod scanner { use crate::arraylist::List; use std::io::{stdin, BufReader, Bytes, Read, Stdin}; use std::str::FromStr; pub struct Scanner { buf: Bytes>, } impl Scanner { pub fn new() -> Scanner { Scanner { buf: BufReader::new(stdin()).bytes(), } } pub fn read_next(&mut self) -> Option { let token = self .buf .by_ref() .map(|c| c.unwrap() as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect::(); token.parse::().ok() } pub fn read(&mut self) -> T { self.read_next().unwrap() } pub fn readn(&mut self, n: i32) -> List { (0..n).map(|_| self.read::()).collect() } pub fn chars(&mut self) -> List { self.read::().chars().collect() } } } pub mod prime_number { use crate::arraylist::List; use crate::data_structure::counter::Counter; pub fn is_prime(n: i64) -> bool { for i in (2..).take_while(|i| i * i <= n) { if n % i == 0 { return false; } } n != 1 } pub fn divisors(n: i64) -> List { let mut ret = List::new(); for i in (1..).take_while(|i| i * i <= n) { if n % i == 0 { ret.push(i); if i != n / i { ret.push(n / i); } } } ret } pub fn prime_factors(n_: i64) -> Counter { let mut ret = Counter::new(); let n = std::cell::Cell::new(n_); for i in (2..).take_while(|&i| i * i <= n.get()) { while n.get() % i == 0 { ret[i] += 1; n.set(n.get() / i); } } if n.get() != 1 { ret[n.get()] = 1; } ret } pub fn sieve(n: i32) -> (List, List) { let mut primes = List::new(); let mut is_prime = List::init(true, n + 1); is_prime[0] = false; is_prime[1] = false; for i in 2..n + 1 { if is_prime[i] { primes.push(i); for j in (2..).map(|j| j * i).take_while(|&j| j <= n) { is_prime[j] = false; } } } (primes, is_prime) } } pub mod data_structure { pub mod counter { use std::collections::HashMap; use std::hash::Hash; use std::ops::*; #[derive(Clone, Debug)] pub struct Counter { pub cnt: HashMap, pub d: i64, } impl Counter { pub fn new() -> Counter { Counter { cnt: HashMap::new(), d: 0, } } #[doc = " Remove key when the value <= 0"] pub fn dec(&mut self, key: K, delta: i64) { if self.by_ref(&key) - delta <= 0 { self.remove(&key); } else { *self.cnt.get_mut(&key).unwrap() -= delta; } } pub fn by_ref(&self, key: &K) -> i64 { *self.cnt.get(key).unwrap_or(&self.d) } } impl Deref for Counter { type Target = HashMap; fn deref(&self) -> &Self::Target { &self.cnt } } impl DerefMut for Counter { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.cnt } } impl Index for Counter { type Output = i64; fn index(&self, index: K) -> &Self::Output { self.cnt.get(&index).unwrap_or(&self.d) } } impl IndexMut for Counter { fn index_mut(&mut self, index: K) -> &mut i64 { if !self.cnt.contains_key(&index) { self.cnt.insert(index.clone(), self.d); } self.cnt.get_mut(&index).unwrap() } } impl std::iter::FromIterator for Counter { fn from_iter>(iter: T) -> Self { let mut cnt = HashMap::new(); for i in iter { *cnt.entry(i).or_insert(0) += 1; } Counter { cnt, d: 0 } } } impl Add for Counter { type Output = Counter; fn add(self, other: Counter) -> Counter { let mut ret = Counter::new(); for (k, v) in self.iter().chain(other.iter()) { ret[k.clone()] += *v; } ret } } impl AddAssign for Counter { fn add_assign(&mut self, other: Self) { *self = self.clone().add(other); } } } } pub mod ext { pub mod range { use crate::independent::integer::Int; use std::cmp::{max, min}; use std::ops::{Bound, Range, RangeBounds, RangeInclusive}; pub trait RangeEx { fn width(&self) -> T; fn empty(&self) -> bool; fn contain_range(&self, inner: &Self) -> bool; fn separate_range(&self, other: &Self) -> bool; type ReturnRange; fn overlap(&self, other: &Self) -> Self::ReturnRange; } impl RangeEx for Range { fn width(&self) -> T { if self.empty() { T::zero() } else { self.end - self.start } } fn empty(&self) -> bool { !(self.start < self.end) } fn contain_range(&self, inner: &Self) -> bool { self.start <= inner.start && inner.end <= self.end } fn separate_range(&self, other: &Self) -> bool { self.end <= other.start || other.end <= self.start } type ReturnRange = Range; fn overlap(&self, other: &Self) -> Self::ReturnRange { let left = max(self.start, other.start); let right = min(self.end, other.end); left..right } } impl RangeEx for RangeInclusive { fn width(&self) -> T { if self.empty() { T::zero() } else { *self.end() - *self.start() + T::one() } } fn empty(&self) -> bool { !(self.start() <= self.end()) } fn contain_range(&self, inner: &Self) -> bool { self.start() <= inner.start() && inner.end() <= self.end() } fn separate_range(&self, other: &Self) -> bool { self.end() <= other.start() || other.end() <= self.start() } type ReturnRange = RangeInclusive; fn overlap(&self, other: &Self) -> Self::ReturnRange { let left = *max(self.start(), other.start()); let right = *min(self.end(), other.end()); left..=right } } pub trait IntRangeBounds: RangeBounds { #[doc = " inclusive"] fn lower_bound(&self, lower_bound: U) -> U { match self.start_bound() { Bound::Included(x) => max(lower_bound, *x), Bound::Excluded(x) => max(lower_bound, *x + U::one()), Bound::Unbounded => lower_bound, } } #[doc = " exclusive"] fn upper_bound(&self, upper_bound: U) -> U { match self.end_bound() { Bound::Included(x) => min(upper_bound, *x + U::one()), Bound::Excluded(x) => min(upper_bound, *x), Bound::Unbounded => upper_bound, } } fn to_harfopen(&self, lb: U, ub: U) -> Range { self.lower_bound(lb)..self.upper_bound(ub) } } impl IntRangeBounds for T where T: RangeBounds {} } } pub mod macros { #[macro_export] macro_rules ! for_ { ( $ init : stmt ; $ cond : expr ; $ incr : expr , $ body : block ) => { $ init while $ cond { $ body $ incr ; } } ; } #[macro_export] macro_rules! chrange { ( $ x : expr , $ r : expr ) => {{ let r = $r; match std::ops::RangeBounds::start_bound(&r) { std::ops::Bound::Included(x) => { $crate::chmax!($x, *x); } std::ops::Bound::Excluded(x) => { $crate::chmax!($x, *x + 1); } _ => (), } match std::ops::RangeBounds::end_bound(&r) { std::ops::Bound::Included(x) => { $crate::chmin!($x, *x); } std::ops::Bound::Excluded(x) => { $crate::chmin!($x, *x - 1); } _ => (), } }}; } #[macro_export] macro_rules! chmax { ( $ x : expr , $ y : expr ) => { if $x < $y { $x = $y; true } else { false } }; } #[macro_export] macro_rules! chmin { ( $ x : expr , $ y : expr ) => { if $x > $y { $x = $y; true } else { false } }; } #[macro_export] macro_rules ! min { ( $ a : expr $ ( , ) * ) => { { $ a } } ; ( $ a : expr , $ b : expr $ ( , ) * ) => { { std :: cmp :: min ( $ a , $ b ) } } ; ( $ a : expr , $ ( $ rest : expr ) ,+ $ ( , ) * ) => { { std :: cmp :: min ( $ a , min ! ( $ ( $ rest ) ,+ ) ) } } ; } #[macro_export] macro_rules ! max { ( $ a : expr $ ( , ) * ) => { { $ a } } ; ( $ a : expr , $ b : expr $ ( , ) * ) => { { std :: cmp :: max ( $ a , $ b ) } } ; ( $ a : expr , $ ( $ rest : expr ) ,+ $ ( , ) * ) => { { std :: cmp :: max ( $ a , max ! ( $ ( $ rest ) ,+ ) ) } } ; } #[macro_export] macro_rules ! assign { ( $ arr : ident $ ( [ $ a : expr ] ) + = $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , = , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + += $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , += , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + -= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , -= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + |= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , |= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + &= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , &= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + ^= $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , default ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + min $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , min ) ; } ; ( $ arr : ident $ ( [ $ a : expr ] ) + max $ right : expr ) => { assign ! ( $ arr , $ ( [ $ a ] ) + , ^= , $ right , max ) ; } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , default ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { let tmp = $ right ; $ arr [ head ] $ op tmp ; } } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , min ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { let tmp = $ right ; $ arr [ head ] = std :: cmp :: min ( $ arr [ head ] , tmp ) ; } } ; ( $ arr : expr , [ $ head : expr ] , $ op : tt , $ right : expr , max ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { let tmp = $ right ; $ arr [ head ] = std :: cmp :: max ( $ arr [ head ] , tmp ) ; } } ; ( $ arr : expr , [ $ head : expr ] $ ( [ $ a : expr ] ) +, $ op : tt , $ right : expr , $ kind : ident ) => { let head = $ head ; if ( 0 ..$ arr . ilen ( ) ) . contains ( &$ head ) { assign ! ( $ arr [ head ] , $ ( [ $ a ] ) +, $ op , $ right , $ kind ) ; } } ; } #[macro_export] macro_rules! unwrap { ( $ arg : expr ) => {{ let tmp = $arg; if tmp.is_none() { return; } tmp.unwrap() }}; } #[macro_export] macro_rules! swap { ( $ a : expr , $ b : expr ) => { let tmp = $a; $a = $b; $b = tmp; }; } }