#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define maxpq priority_queue<int>
#define minpq priority_queue<int ,vector<int>,greater<int>>
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define bits(n) __builtin_popcount(n)
#define prec(n) fixed<<setprecision(n)
#define rr return 0
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;


void solve(){

map<int,int> m;
ll n;
cin>>n;
ll a[n];
for0(i,n) cin>>a[i];
ll ans=0;
for(ll i=n-1;i>=0;i--){
ans+=(n-1-i-m[a[i]]);
m[a[i]]++;
}
cout<<ans<<endl;




}







int main()
{
fio;
ll t=1;
//cin>>t;
while(t--)
solve();
rr ;
}

#include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}


template<typename T, T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T, T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T, T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}


// [0, n]
template<typename T>
vector<T> powers(int n,T x){
  vector<T> po(n+1,T(1));
  for(int i=0;i<n;i++) po[i+1]=po[i]*x;
  return po;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n,m;
  cin>>n>>m;

  using M = Mint<int, 998244353>;
  vector<M> way(n,0);
  for(int h=1;h<=m;h++){
    M res{1};
    for(int i=0;i<n;i++){
      way[i]+=res;
      res*=M(m-h);
    }
  }

  auto po=powers(n,M(m));

  M ans=M(n)*po[n];
  for(int w=0;w+2<=n;w++)
    ans-=M(n-(w+2)+1)*po[n-(w+2)]*way[w];
  //cout<<way[0]<<endl;
  cout<<ans<<newl;
  return 0;
}
