package main import ( "bufio" "fmt" "os" "sort" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 2 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { n := getNextInt(scanner) aa := make([]int, n) for i := 0; i < n; i++ { aa[i] = getNextInt(scanner) } for i := 1; i < n; i++ { aa[i] += aa[i-1] } dd := divisors(aa[n-1]) for i := 0; i < len(dd); i++ { if ok(aa[n-1]/dd[i], dd[i], aa) { fmt.Fprintln(writer, aa[n-1]/dd[i]) return } } } func ok(c, d int, aa []int) bool { n := len(aa) for i := 0; i < c; i++ { l := -1 r := n for l+1 < r { m := (l + r) >> 1 if aa[m] < d*(i+1) { l = m continue } r = m } if r == n { return false } if aa[r] != d*(i+1) { return false } } return true } func divisors(n int) []int { dd := make([]int, 0) dd = append(dd, n) dd = append(dd, 1) for i := 2; i*i <= n; i++ { if n%i == 0 { dd = append(dd, i) if i*i == n { continue } dd = append(dd, n/i) } } sort.Ints(dd) return dd }