#include <bits/stdc++.h>
using namespace std;
const int N = 3e6 + 20, M = 1e6 + 10, mod = 1e9 + 7, inf = 1e9;
int a[N], n;
long long c[N], tot;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), tot += a[i];
  long long M = tot / n;
  c[0] = 0;
  for (int i = 1; i <= n; i++) c[i] = c[i - 1] + a[i] - M;
  sort(c, c + n);
  map<long long, int> mp;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    mp[c[i]]++;
    ans = max(ans, mp[c[i]]);
  }
  printf("%d\n", n - ans);
  return 0;
}
