#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const int maxn = 300000 + 10;
const ll mod = 19260817;
int n, a[maxn];
int ref[maxn], num[maxn], num_cnt;
ll c1[maxn] = {0}, c2[maxn] = {0};
inline void Update(ll *arr, int pos, int val){
for(int i = pos; i <= n; i += i & -i) arr[i] = (arr[i] + val) % mod;
}
inline ll Query(ll *arr, int pos){
ll s = 0;
for(int i = pos; i; i -= i & -i) s = (s + arr[i]) % mod;
return s;
}
ll f[maxn], g[maxn];
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++){
scanf("%d", a + i);
num[i] = a[i];
}
sort(num + 1, num + n + 1);
num_cnt = unique(num + 1, num + n + 1) - (num + 1);
for(int t, i = 1; i <= n; i++){
t = lower_bound(num + 1, num + num_cnt + 1, a[i]) - num;
ref[t] = a[i] % mod;
a[i] = t;
}
for(int i = 1; i <= n; i++){
f[i] = Query(c1, a[i] - 1);
Update(c1, a[i], ref[a[i]]);
}
for(int i = n; i; i--){
g[i] = Query(c2, n) - Query(c2, a[i]);
if(g[i] < 0) g[i] += mod;
Update(c2, a[i], ref[a[i]]);
}
ll ans = 0;
for(int i = 1; i <= n; i++)
ans = (ans + f[i] * g[i] % mod * ref[a[i]]) % mod;
printf("%lld\n", ans);
return 0;
}