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
 92
 93
 94
 95
 96
 97
 98
 99
100
101
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <numeric>
#include <deque>

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

	/*
	std::cout << "100000\n";
	long long sumaa = 0;
	for (int i = 0; i < 99999; ++i)
	{
		std::cout << i << " ";
		sumaa += i;
	}
	std::cout << (97772875200ll - sumaa) << "\n";
	return 0;*/



	int n;
	std::cin >> n;
	std::vector<long long> bursztyny;
	for (int i = 0; i < n; ++i)
	{
		int bursztyn;
		std::cin >> bursztyn;
		bursztyny.push_back(bursztyn);
	}
	long long suma = 0;
	for (int i = 0; i < n; ++i)
	{
		suma += bursztyny[i];
	}
	std::vector<long long> dzielniki;
	for (long long i = 1; i * i <= suma; ++i)
	{
		if (suma % i == 0)
		{
			dzielniki.push_back(i);
			dzielniki.push_back(suma / i);
		}
	}
	std::sort(dzielniki.begin(), dzielniki.end());
	std::vector<bool> czyDzielnikOK(dzielniki.size(), true);
	//std::reverse(dzielniki.begin(), dzielniki.end());
	std::vector<long long> fale(n);
	

	long long maxDzielnik = 1;
	for (int i = 0; i < dzielniki.size(); ++i)
	{
		if (dzielniki[i] == 3)
		{
			std::cerr << "AA\n";
		}
		if (!czyDzielnikOK[i])
			continue;
		long long dzielnik = dzielniki[i];
		long long sumaFal = 0;
		bool czySukces = true;
		for (int j = 0; j < n; ++j)
		{
			if (j >= dzielnik)
				sumaFal -= fale[j - dzielnik];

			fale[j] = bursztyny[j] - sumaFal;
			sumaFal += fale[j];
			if (fale[j] < 0)
			{
				czySukces = false;
				break;
			}
		}
		if (n >= dzielnik)
			sumaFal -= fale[n - dzielnik];
		if (sumaFal==0 && czySukces)
		{
			maxDzielnik = std::max(maxDzielnik, dzielnik);
		}
		else
		{
			for (int j = 0; j < dzielniki.size(); ++j)
			{
				if (dzielniki[j] % dzielnik == 0)
					czyDzielnikOK[j] = false;
			}
		}
	}
	std::cout << maxDzielnik << "\n";
	return 0;
}