func_code_string: #include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int n, a[500010], b[500010], c[500010], bit[500010];   void init() {     for (int i = 1; i <= n; i++) {       bit[i] = 0;     }   }   int lowbit(int x) { return x & (-x); }   void add(int u, int x) {     for (; u <= n; u += lowbit(u)) {       bit[u] = (bit[u] + x) % mod;     }   }   int sum(int u) {     int res = 0;     for (; u >= 1; u -= lowbit(u)) {       res = (res + bit[u]) % mod;     }     return res;   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);       b[i] = a[i];     }     sort(b + 1, b + n + 1);     for (int i = 1; i <= n; i++) {       a[i] = lower_bound(b + 1, b + n + 1, a[i]) - b;     }     int ans = 0;     init();     for (int i = 1; i <= n; i++) {       ans = (ans + 1LL * b[a[i]] * sum(a[i]) % mod * (n - i + 1) % mod) % mod;       c[a[i]] += sum(a[i]) * (n - i + 1);       add(a[i], i);     }     init();     for (int i = n; i >= 1; i--) {       ans = (ans + 1LL * b[a[i]] * sum(a[i]) % mod * i % mod) % mod;       c[a[i]] += sum(a[i]) * i;       add(a[i], n - i + 1);     }     for (int i = 1; i <= n; i++) {       ans = (ans + 1LL * b[a[i]] * i % mod * (n - i + 1) % mod) % mod;       c[a[i]] += i * (n - i + 1);     }     printf( %d n , ans);     return 0;   }   