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) m := map[int]int{} for i := 0; i < c; i++ { m[d*(i+1)] = 1 } for i := 0; i < n; i++ { delete(m, aa[i]) } return len(m) == 0 } func before(i int, aa []int) int { if i == 0 { return 0 } return aa[i-1] } 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 }