#include using namespace std; using ll = long long; #ifdef LOCAL #include #else #define debug(...) #endif int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); int N; cin >> N; vector A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll ans = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) ans += abs(i - j) * abs(A[i] - A[j]); } cout << ans << '\n'; }