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
#ifdef _MSC_VER
  #ifndef __GNUC__
    #pragma warning(disable: 4996)
  #endif
  #define main main0
  extern char* nazwa;
#endif
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long           ll;
typedef unsigned long long ull;
typedef unsigned int      uint;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  ll suma = 0;
  cin >> n;
  if(n == 1) {
    cout << '1' << endl;
    return 0;
  }
  vector<int> segmentOd(n + 1);
  vector<int> segmentDo(n + 1);
  for(int i = 0; i < n; ++i) {
    cin >> segmentOd[i];
    suma += segmentOd[i];
  }
  //int maxSzerokosc = n; // gdy sa zera - max odleglosc miedzy zerami
  
  for(int szerokosc = n;  szerokosc > 1; --szerokosc) {
    if(suma % szerokosc != 0) // liczba bursztynow musi byc podzielna przez rozmiar fal
      continue;
    fill_n(segmentDo.begin(), n + 1, 0);
    segmentDo[szerokosc] = segmentOd[0];
    bool poprawne = true;
    for(int pozycja = 1, koniec = szerokosc + 1; pozycja <= n; ++pozycja, ++koniec) {
      int liczbaFal = segmentOd[pozycja-1] - segmentDo[pozycja];
      if(liczbaFal > segmentOd[pozycja]) {
        poprawne = false;
        break;
      }
      if(segmentOd[pozycja] > liczbaFal)
        if(koniec <= n)
          segmentDo[koniec] = segmentOd[pozycja] - liczbaFal;
        else {
          poprawne = false;
          break;
        }
    }
    if(poprawne) {
      cout << szerokosc << endl;
      return 0;
    }
  }

  cout << '1' << endl;
  return 0;
}