1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define N 100000

int a[N];
int c[20000];
int s[N];

int cmp(const void* a, const void* b) {
  const int x = *(const int*)a;
  const int y = *(const int*)b;
  if(x > y) return -1;
  if(x < y) return 1;
  return 0;
}

int main() {
  int n = 0;
  scanf("%d", &n);
  int max_l = n;
  int max_r = n;
  bool ok = true;
  long long suma = 0;
  scanf("%d", &a[0]);
  suma += a[0];
  for(int i = 1; i < n; i++) {
    scanf("%d", &a[i]);
    suma += a[i];
    if(ok && a[i] < a[i-1]) {
      max_l = i;
      ok = false;
    }
  }
  int j = 1;
  for(int i = n - 2; i>= 0; i--) {
    if(a[i] < a[i + 1]) {
      max_r = j;
      break;
    }
    j++;
  }
  if(max_r < max_l) {
    max_l = max_r;
  }
  int c_c = 0;
  long long i = 1;
  while(1) {
    if(i > max_l || i > suma/i) {
      break;
    }
    if(suma % i == 0) {
      c[c_c] = i;
      c_c++;
      if(suma / i <= max_l && suma / i != i) {
        c[c_c] = (int) (suma / i);
        c_c++;
      }
    }
    i++;
  }
  qsort(c, c_c, sizeof(int), cmp);
  for(int j = 0; j < c_c - 1; j++) {
    int sz = c[j];
    memset(s, 0, n*sizeof(int));
    s[0] = 0;
    s[sz-1] = a[0];
    bool ok = true;
    for(int i = 1; i < n; i++) {
      int w = a[i] - a[i-1] + s[i - 1];
      if(w < 0) {
        ok = false;
        break;
      }
      if(w > 0) {
        if(i + sz > n) {
          ok = false;
          break;
        }
        s[i + sz - 1] = w;
      }
    }
    if(ok) {
      printf("%d\n", sz);
      return 0;
    }
  }
  printf("1\n");
  return 0;
}