usingnamespacestd; usingnamespace FAST_IO; const ll mod = 1e9 + 7; constint INF = 0x3f3f3f3f; const ll INF_LL = 0x3f3f3f3f3f3f3f3f; constdouble eps = 1e-5; constint maxn = 1e3 + 10; constint maxm = 1e5 + 10; int t, n, m, k; int a[maxn]; intmain() { // #define COMP_DATA #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); #endif ios::sync_with_stdio(false); cin.tie(0); int tcase;
cin >> n; int minx = INF; int ans = 0; int sum = 0; // ans1 = 0*x1 + 1*x2 +...+(n-1)*xn // ans2 = (n-1)x1 + 0*x2 + 1*x3 + ... + (n-2)*xn // delt = -nx1 + sum // ans2 = ans1 + nx1 - sum // ans - sum + n * x1 for (int i = 1, x; i <= n; i++) { cin >> a[i]; sum += a[i]; ans += (i - 1) * a[i]; } minx = min(minx, ans); for (int i = 2; i <= n; i++) { ans = ans - sum + n * a[i - 1]; minx = min(ans, minx); } cout << minx << endl; return0; }