#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

template<class T> bool takemax(T& a, T b) {bool Z=(a<b); if(Z)a=b; return Z;}
template<class T> bool takemin(T& a, T b) {bool Z=(a>b); if(Z)a=b; return Z;}

const int MAXN = 100007;
LL a[MAXN], ta[MAXN];
int n;

void ex_gcd (LL a, LL b, LL& gcd, LL& x, LL& y)
{
     if (b == 0)  { x = 1; y = 0; gcd = a; }
     else  { ex_gcd (b, a % b, gcd, y, x);  y -= x * (a / b); }
}

LL cal(LL A, LL B, LL C)
{
	LL g, x, y, dx, dy;
	ex_gcd(A, B, g, x, y);

	if(C % g)	return 0;

    x *= C / g;
    y *= C / g;

	dx = B / g, dy = A / g;
	if(x >= 0 && y >= 0)
	{
		LL t = (y / dy);
		x += t * dx;
		return (x / dx) + 1;
	}
	else if(x < 0)
	{
		LL t = (-x) / dx + LL((-x) % dx);
		y -= t * dy;
		return (y / dy) + 1;
	}
	else
	{
		LL t = (-y) / dy + LL((-y) % dy);
		x -= t * dx;
		return (x / dx) + 1;
	}
}

LL gao(LL avg)
{
	if(avg % n)	return 0;
	LL v_avg = avg / n;
	if(v_avg + avg > ta[1])	return 0;

    for(int i=1;i<=n;i++)
        a[i] = ta[i];

	for(int i=1;i<=n;i++)
		a[i] -= v_avg + avg;

	for(int i=2;i<=n;i++)
		if((a[i] - a[i-1]) % avg)
			return 0;
		else
			a[i] = a[i-1];
	LL rest = a[1];

	//cout<<rest<<endl;

	if(rest == 0)	return 1;

	return cal(avg, v_avg, rest);
}

int main()
{
    //freopen("c.txt","r",stdin);
	while(1)
	{
		scanf("%d", &n);
		if(n == 0)	break;
		LL sum = 0;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld", &ta[i]);
			sum += ta[i];
		}
		sort(ta+1, ta+n+1);
		LL ans = 0;

        //cout<<sum<<endl;
		for(LL i=2;i*i<=sum;i++)
			if(sum % i == 0)
			{
				ans += gao(i);
				if(i * i != sum)
					ans += gao(sum / i);
			}
		printf("%lld\n", ans);
	}

	return 0;
}

