文件目录

#include <iostream>
using namespace std;
int main()
{
    int n, a[105] = {}, s = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        s += a[i];
    }
    int avg = s / n;
    for (int i = 1; i <= n; i++)
    {
        a[i] -= avg;
    }
    bool f = true;
    int k = 0, id = 0, ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i] == 0)
            continue;
        k += a[i]; // 累计差额
        if (f)
        {
            id = i; // 差额起点
            f = false;
        }
        if (k == 0)
        {
            ans += i - id;
            f = true;
        }
    }
    cout << ans;
    return 0;
}