output_description: Print the inversion number of B, modulo 10^9 + 7.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N K
      A_0 A_1 ... A_{N - 1}
attempt: import sys
  
  input = sys.stdin.readline
  
  
  def read():
      N, K = map(int, input().strip().split())
      A = list(map(int, input().strip().split()))
      return N, K, A
  
  
  class ModInt(int):
  
      MOD = 10**9 + 7
  
      def __new__(cls, x, *args, **kwargs):
          return super().__new__(cls, x % ModInt.MOD)
  
      def __add__(self, other):
          return ModInt(super().__add__(other) % ModInt.MOD)
  
      def __radd__(self, other):
          return ModInt(super().__radd__(other) % ModInt.MOD)
  
      def __mul__(self, other):
          return ModInt(super().__mul__(other) % ModInt.MOD)
  
      def __rmul__(self, other):
          return ModInt(super().__rmul__(other) % ModInt.MOD)
  
      def __pow__(self, other, *args):
          return ModInt(super().__pow__(other, ModInt.MOD))
  
      def __rpow__(self, other, *args):
          raise NotImplementedError()
  
      def __truediv__(self, other):
          return ModInt(super().__mul__(pow(other, ModInt.MOD - 2, ModInt.MOD)))
  
      def __floordiv__(self, other):
          return self.__truediv__(other)
  
      def __rtruediv__(self, other):
          return ModInt(self.__pow__(ModInt.MOD - 2).__mul__(other))
  
      def __rfloordiv__(self, other):
          return self.__rtruediv__(other)
  
  
  def solve(N, K, A):
      ModInt.MOD = 10**9 + 7
      N = len(A)
      k = ModInt(K)
      t0 = k * (k + 1) // 2  # 三角数
      t1 = (k - 1) * k // 2
  
      c0 = 0
      c1 = 0
      for i in range(N):
          for j in range(i + 1, N):
              if A[i] > A[j]:
                  c0 += 1
              elif A[i] < A[j]:
                  c1 += 1
      return c0 * t0 + c1 * t1
  
  
  if __name__ == "__main__":
      inputs = read()
      outputs = solve(*inputs)
      if outputs is not None:
          print("%s" % str(outputs))
  
problem_description: Statement
  
  We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
  
  Let B be a sequence of K \times N integers obtained by concatenating K copies
  of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
  
  Find the inversion number of B, modulo 10^9 + 7.
  
  Here the inversion number of B is defined as the number of ordered pairs of
  integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
samples: [{"input": "2 2\n    2 1", "output": "3\n    \n\nIn this case, B~=~2,~1,~2,~1. We have:\n\n  * B_0 > B_1\n  * B_0 > B_3\n  * B_2 > B_3\n\nThus, the inversion number of B is 3.\n\n* * *"}, {"input": "3 5\n    1 1 1", "output": "0\n    \n\nA may contain multiple occurrences of the same number.\n\n* * *"}, {"input": "10 998244353\n    10 9 8 7 5 6 3 4 2 1", "output": "185297239\n    \n\nBe sure to print the output modulo 10^9 + 7."}]