#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
	const int m=1000000007;
	int n, p;
	cin>>n>>p;

	int ans=p-1;
	int c=p-2;
	for(int d=n-1; d>0; d>>=1){
		if(d&1) ans=(ll)ans*c%m;
		c=(ll)c*c%m;
	}

	cout<<ans<<endl;
	return 0;
}

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>
#include<math.h>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
//const ll mod=1000000007;
const ll mod=998244353;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll N;
    cin>>N;
    vector<ll> A(N);
    rep(i,N) cin>>A.at(i);
    sort(ALLOF(A));

    ll ans=0;
    rep(i,N) ans=(ans+A.at(i)*A.at(i))%mod;

    ll rui=A.at(N-1);
    for(ll i=N-2;i>=0;i--){
        ans=(ans+A.at(i)*rui)%mod;
        rui=(2*rui+A.at(i))%mod;
    }
    cout<<ans%mod<<endl;
    return 0;
}