Language: C++

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

struct mint {
    LL x; // typedef long long LL;
    mint(LL x=0):x(x%mod){}
    mint& operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator-=(const mint a) {
      if ((x += mod-a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator*=(const mint a) {
      (x *= a.x) %= mod;
      return *this;
    }
    mint operator+(const mint a) const {
      mint res(*this);
      return res+=a;
    }
    mint operator-(const mint a) const {
      mint res(*this);
      return res-=a;
    }
    mint operator*(const mint a) const {
      mint res(*this);
      return res*=a;
    }
    mint pow(LL t) const {
      if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
      if (t&1) a *= *this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a) {
      return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
      mint res(*this);
      return res/=a;
    }
  };

int memo1[2010] = {}; //A内の普通の転倒数
int memo2[2010] = {}; //A内の全ての組み合わせでの転倒数

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; LL K; cin >> N >> K;
  assert(k < 1e7);
    VI A(N);
    REP(i,N) cin >> A[i];
    REP(i,N){
        int tmp = 0;
        REP(j,i){
            if(A[i] < A[j]) tmp++;
        }
        memo1[i] = tmp;
    }
    REP(i,N){
        int tmp = 0;
        REP(j,N){
            if(A[i] < A[j]) tmp++;
        }
        memo2[i] = tmp;
    }

    LL ans = 0;
    REP(i,N){
        ans += (memo1[i]+(memo1[i] + (K-1) * 1LL * memo2[i])) * K / 2;
        ans %= mod;
    }
    cout << ans << endl;

}


Compiler output:
a.cc: In function 'int main(int, const char**)':
a.cc:116:10: error: 'k' was not declared in this scope
  116 |   assert(k < 1e7);
      |          ^
a.cc:116:3: error: 'assert' was not declared in this scope
  116 |   assert(k < 1e7);
      |   ^~~~~~
a.cc:19:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
   18 | #include <iomanip>
  +++ |+#include <cassert>
   19 |