#include <bits/stdc++.h>
using namespace std;
#define FNAME "test"
const int N = 2e5 + 5;
const int M = 998244353;
const int modinv2 = (M + 1) / 2;
int n, m;
pair<int,int> booth[N];
int last[N];
int ans;
void Task() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cout << fixed << setprecision(9);
if (fopen(FNAME".inp","r")) {
freopen(FNAME".inp","r",stdin);
freopen(FNAME".out","w",stdout);
}
}
void compress() {
set<int> s;
for (int i = 1; i <= n; i++) s.insert(booth[i].first);
vector<int> b(s.begin(), s.end());
for (int i = 1; i <= n; i++) booth[i].second = lower_bound(b.begin(), b.end(), booth[i].first) - b.begin() + 1;
}
void Input() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> booth[i].first;
compress();
}
int cnt(int n) {
return (((1LL * n * (n + 1)) % M) * modinv2) % M;
}
void solve() {
memset(last, 0, sizeof(last));
ans = 0;
int sum = cnt(m);
for (int i = 1; i <= n; i++) {
if (last[booth[i].second] == 0) sum = (sum + M - booth[i].first) % M;
int l = last[booth[i].second] + 1, r = i - 1;
if (l <= r) ans = (ans + ((1LL * cnt(r - l + 1) * booth[i].first) % M)) % M;
last[booth[i].second] = i;
}
for (int i = 1; i <= n; i++) {
if (last[booth[i].second] != 0) {
int l = last[booth[i].second] + 1, r = n;
if (l <= r) ans = (ans + ((1LL * cnt(r - l + 1) * booth[i].first) % M)) % M;
last[booth[i].second] = 0;
}
}
int tmp = cnt(n);
sum = (1LL * sum * tmp) % M;
ans = (ans + sum) % M;
cout << ans << '\n';
}
void Solve() {
//Your Code
Input();
solve();
}
int main() {
Task();
Solve();
cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms";
return 37^37;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBGTkFNRSAidGVzdCIKCmNvbnN0IGludCBOID0gMmU1ICsgNTsKY29uc3QgaW50IE0gPSA5OTgyNDQzNTM7C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