Language: C++

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((ll)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
typedef long long ll;
ll INF = 1e18;
using namespace std;

  const int MOD = 1000000007;
  

  template< int mod >
struct ModInt {
  int x;

  ModInt() : x(0) {}

  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

  ModInt &operator+=(const ModInt &p) {
   if((x += p.x) >= mod) x -= mod;
   return *this;
 }

  ModInt &operator-=(const ModInt &p) {
   if((x += mod - p.x) >= mod) x -= mod;
   return *this;
  }

  ModInt &operator*=(const ModInt &p) {
   x = (int) (1LL * x * p.x % mod);
   return *this;
  }

  ModInt &operator/=(const ModInt &p) {
   *this *= p.inverse();
   return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

  bool operator==(const ModInt &p) const { return x == p.x; }

  bool operator!=(const ModInt &p) const { return x != p.x; }

  ModInt inverse() const {
   int a = x, b = mod, u = 1, v = 0, t;
   while(b > 0) {
     t = a / b;
     swap(a -= t * b, b);
     swap(u -= t * v, v);
   }
   return ModInt(u);
  }

  ModInt pow(int64_t n) const {
   ModInt ret(1), mul(x);
   while(n > 0) {
     if(n & 1) ret *= mul;
     mul *= mul;
     n >>= 1;
   }
   return ret;
  }

  friend ostream &operator<<(ostream &os, const ModInt &p) {
   return os << p.x;
  }

  friend istream &operator>>(istream &is, ModInt &a) {
   int64_t t;
   is >> t;
   a = ModInt< mod >(t);
   return (is);
  }

  static int get_mod() { return mod; }
};

using modint = ModInt< MOD >;



int main(){
  ll N,K;
  cin >> N >> K;
  
  vector<ll> S1(N);
  vector<ll> S2(N);
  
  vector<ll> A(N);
  
  rep(i,N){
    ll a;
    cin >> A[i];
  }
  
  rep(i,N){
    ll count1 = 0;
    ll count2 = 0;
    rep(j,N){
      if(A[i]>A[j]){
        count1 += 1;
        if(j>i)count2 += 1;
      }
    }
    S1[i] = count1;
    S2[i] = count2;
  }
  
  ll sum1 = 0;
  ll sum2 = 0;
  
  for(ll n: S1){
    sum1 += n;
  }
  
  for(ll n: S2){
    sum2 += n;
  }
  
  // ll ans = ( ( (sum2%MOD) * (K%MOD) )%MOD ) + ( (((sum1%MOD)*(((K-1)%MOD)*(K%MOD))%MOD)%MOD)*modinv(2, MOD)%MOD );
  ll ans = 0;
  
  modint s1,s2,k,km1,n2;
  s1 = sum1;
  s2 = sum2;
  k = K;
  km1 = K-1;
  n2 = 2;

  ans = ( ( sum2 * K )%MOD ) + ( ((sum1*((K-1)/2*K)%MOD)%MOD) );
  ans = (s2 * k + s1*km1*k/n2);
  
  cout << ans << endl;




  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:149:17: error: cannot convert 'ModInt<1000000007>' to 'll' {aka 'long long int'} in assignment
  149 |   ans = (s2 * k + s1*km1*k/n2);
      |         ~~~~~~~~^~~~~~~~~~~~~~
      |                 |
      |                 ModInt<1000000007>