Language: C++

v#include <bits/stdc++.h>

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;
template <long long Mod = MOD>
class Modint {
 public:
  long long v;

  Modint(const Modint &x) { v = x.v; }
  explicit Modint(int x) {
    if (x < 0 or Mod <= x) x %= Mod;
    if (x < 0) x += Mod;
    v = x;
  }
  explicit Modint(long long x) {
    if (x < 0 or Mod <= x) x %= Mod;
    if (x < 0) x += Mod;
    v = x;
  }
  explicit Modint(unsigned x) {
    if (Mod <= x) x %= Mod;
    v = x;
  }
  explicit Modint(unsigned long long x) {
    if (Mod <= x) x %= Mod;
    v = x;
  }
  template <typename T>
  explicit Modint(T x) {
    if (x < 0 or Mod <= x) x %= Mod;
    v = x;
  }
  Modint() : v(0) {}
  long long get() const { return v; }
  Modint mpow(Modint &n) const { return mpow(n.v); }
  Modint mpow(long long n) const {
    long long i = 1, p = v;
    Modint ret(1);
    while (i <= n) {
      if (i & n) ret *= p;
      i = (i << 1);
      p = (p * p) % Mod;
    }
    return ret;
  }
  Modint operator-() const { return (v ? Modint(Mod - v) : Modint(0)); }
  explicit operator int() const { return v; }
  explicit operator long long() const { return v; }
  Modint &operator+=(const Modint &a) {
    v = (v + a.v);
    if (v >= Mod) v -= Mod;
    return *this;
  }
  Modint &operator-=(const Modint &a) {
    v = (v - a.v);
    if (v < 0) v += Mod;
    return *this;
  }
  Modint &operator*=(const Modint &a) {
    v = (v * a.v) % Mod;
    return *this;
  }
  Modint &operator/=(const Modint &a) {
    v = (v * a.mpow(Mod - 2).v) % Mod;
    return *this;
  }
  template <class T>
  Modint &operator+=(const T &a) {
    v = (v + Modint(a).v);
    if (v >= Mod) v -= Mod;
    return *this;
  }
  template <class T>
  Modint &operator-=(const T &a) {
    v = (v - Modint(a).v);
    if (v < 0) v += Mod;
    return *this;
  }
  template <class T>
  Modint &operator*=(const T &a) {
    v = (v * Modint(a).v) % Mod;
    return *this;
  }
  template <class T>
  Modint &operator/=(const T &a) {
    v = (v * Modint(a).mpow(Mod - 2).v) % Mod;
    return *this;
  }
  friend Modint operator+(const Modint &a, const Modint &b) {
    return Modint(a) += b;
  }
  friend Modint operator-(const Modint &a, const Modint &b) {
    return Modint(a) -= b;
  }
  friend Modint operator*(const Modint &a, const Modint &b) {
    return Modint(a) *= b;
  }
  friend Modint operator/(const Modint &a, const Modint &b) {
    return Modint(a) /= b;
  }
  template <class T, class U>
  friend Modint operator+(const T &a, const U &b) {
    return Modint(a) += Modint(b);
  }
  template <class T, class U>
  friend Modint operator-(const T &a, const U &b) {
    return Modint(a) -= Modint(b);
  }
  template <class T, class U>
  friend Modint operator*(const T &a, const U &b) {
    return Modint(a) *= Modint(b);
  }
  template <class T, class U>
  friend Modint operator/(const T &a, const U &b) {
    return Modint(a) /= Modint(b);
  }
};

template <long long M>
ostream &operator<<(ostream &os, const Modint<M> m) {
  return os << m.v;
}

class Solver2 {
 public:
  LL n, k;
  vector<int> a, cntr, cnt;
  Solver2(LL n, LL k) : n(n), k(k), a(n), cntr(n), cnt(n){};

  void solve() {
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
        if (a[i] > a[j]) cntr[i]++;
      }
      for (int j = 0; j < n; ++j) {
        if (a[i] > a[j]) cnt[i]++;
      }
    }
    Modint<> ans(0);
    Modint<> ext(0);
    for (int i = 0; i < n; ++i) {
      ext += cnt[i];
    }
    ans += ext * k * (k - 1) / 2;
    Modint<> inter(0);
    for (int i = 0; i < n; ++i) {
      inter += cntr[i];
    }
    ans += inter * k;
    cout << ans << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0, k;
  std::cin >> n >> k;

  Problem::Solver2 sol(n, k);
  sol.solve();
  return 0;
}


Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | v#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'v' does not name a type
    1 | v#include <bits/stdc++.h>
      | ^
a.cc:15:11: error: 'LL' does not name a type
   15 | constexpr LL LINF = 334ll << 53;
      |           ^~
a.cc:17:11: error: 'LL' does not name a type
   17 | constexpr LL MOD = 1E9 + 7;
      |           ^~
a.cc:21:27: error: 'MOD' was not declared in this scope
   21 | template <long long Mod = MOD>
      |                           ^~~
a.cc:137:1: error: 'ostream' does not name a type
  137 | ostream &operator<<(ostream &os, const Modint<M> m) {
      | ^~~~~~~
a.cc:143:3: error: 'LL' does not name a type
  143 |   LL n, k;
      |   ^~
a.cc:144:3: error: 'vector' does not name a type
  144 |   vector<int> a, cntr, cnt;
      |   ^~~~~~
a.cc:145:13: error: expected ')' before 'n'
  145 |   Solver2(LL n, LL k) : n(n), k(k), a(n), cntr(n), cnt(n){};
      |          ~  ^~
      |             )
a.cc: In member function 'void Problem::Solver2::solve()':
a.cc:148:25: error: 'n' was not declared in this scope
  148 |     for (int i = 0; i < n; ++i) {
      |                         ^
a.cc:149:7: error: 'cin' was not declared in this scope
  149 |       cin >> a[i];
      |       ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | v#include <bits/stdc++.h>
a.cc:149:14: error: 'a' was not declared in this scope
  149 |       cin >> a[i];
      |              ^
a.cc:151:25: error: 'n' was not declared in this scope
  151 |     for (int i = 0; i < n; ++i) {
      |                         ^
a.cc:153:13: error: 'a' was not declared in this scope
  153 |         if (a[i] > a[j]) cntr[i]++;
      |             ^
a.cc:153:26: error: 'cntr' was not declared in this scope
  153 |         if (a[i] > a[j]) cntr[i]++;
      |                          ^~~~
a.cc:156:13: error: 'a' was not declared in this scope
  156 |         if (a[i] > a[j]) cnt[i]++;
      |             ^
a.cc:156:26: error: 'cnt' was not declared in this scope; did you mean 'int'?
  156 |         if (a[i] > a[j]) cnt[i]++;
      |                          ^~~
      |                          int
a.cc:159:12: error: template argument 1 is invalid
  159 |     Modint<> ans(0);
      |            ^
a.cc:160:12: error: template argument 1 is invalid
  160 |     Modint<> ext(0);
      |            ^
a.cc:161:25: error: 'n' was not declared in this scope
  161 |     for (int i = 0; i < n; ++i) {
      |                         ^
a.cc:162:14: error: 'cnt' was not declared in this scope; did you mean 'int'?
  162 |       ext += cnt[i];
      |              ^~~
      |              int
a.cc:164:18: error: 'k' was not declared in this scope
  164 |     ans += ext * k * (k - 1) / 2;
      |                  ^
a.cc:165:12: error: template argument 1 is invalid
  165 |     Modint<> inter(0);
      |            ^
a.cc:166:25: error: 'n' was not declared in this scope
  166 |     for (int i = 0; i < n; ++i) {
      |                         ^
a.cc:167:16: error: 'cntr' was not declared in this scope
  167 |       inter += cntr[i];
      |                ^~~~
a.cc:170:5: error: 'cout' was not declared in this scope
  170 |     cout << ans << endl;
      |     ^~~~
a.cc:170:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:170:20: error: 'endl' was not declared in this scope
  170 |     cout << ans << endl;
      |                    ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | v#include <bits/stdc++.h>
a.cc: In function 'int main()':
a.cc:176:8: error: 'cin' is not a member of 'std'
  176 |   std::cin.tie(0);
      |        ^~~
a.cc:176:8: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:177:8: error: 'std::ios_base' has not been declared
  177 |   std::ios_base::sync_with_stdio(false);
      |        ^~~~~~~~
a.cc:180:8: error: 'cin' is not a member of 'std'
  180 |   std::cin >> n >> k;
      |        ^~~
a.cc:180:8: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:182:28: error: no matching function for call to 'Problem::Solver2::Solver2(long long int&, long long int&)'
  182 |   Problem::Solver2 sol(n, k);
      |                            ^
a.cc:141:7: note: candidate: 'constexpr Problem::Solver2::Solver2()'
  141 | class Solver2 {
      |       ^~~~~~~
a.cc:141:7: note:   candidate expects 0 arguments, 2 provided
a.cc:141:7: note: candidate: 'constexpr Problem::Solver2::Solver2(const Problem::Solver2&)'
a.cc:141:7: note:   candidate expects 1 argument, 2 provided
a.cc:141:7: note: candidate: 'constexpr Problem::Solver2::Solver2(Problem::Solver2&&)'
a.cc:141:7: note:   candidate expects 1 argument, 2 provided