#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353;
set<multiset<int>> s[111];
int dp[6333][6333];
int dfs(int n, int k) {
	if (!k) return 1;
	if (!n) return 0;
	n = min(n,k);
	int &ans = dp[n][k];
	if (~ans) return ans;
	return ans = (dfs(n-1,k)+dfs(2*n,k-n))%P;
}

int main() {
	memset(dp,-1,sizeof dp);
	int n, k;
	scanf("%d%d", &k, &n);
	printf("%d\n", dfs(n,k-n));
}


#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a % m + m) % m;}

int main(){
    ll n;
    cin >> n;

    ll rui[n], ruipow[n];
    ll a[n];
    rep(i, n){
        cin >> a[i];

        if(i){
            rui[i] = a[i] + rui[i-1];
            ruipow[i] = a[i]*a[i] + ruipow[i-1];
        }
        else {
            rui[i] = a[i];
            ruipow[i] = a[i] * a[i];
        }
    }

    ll ans = 0;
    rep1(i, n-1){
        ll c1 = i * a[i] * a[i];
        ll c2 = 2 * a[i] * rui[i-1];
        ll c3 = ruipow[i-1];

        // cout << rui[n-1] -  rui[i] << ", " << c3 << endl;

        ans += c1 - c2 + c3;
    }

    cout << ans << endl;
}