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: # coding: utf-8
  import sys
  
  # from operator import itemgetter
  sysread = sys.stdin.buffer.readline
  read = sys.stdin.buffer.read
  # from heapq import heappop, heappush
  # from collections import defaultdict
  sys.setrecursionlimit(10**7)
  import math
  
  
  # from itertools import product, accumulate, combinations, product
  # import bisect# lower_bound etc
  # import numpy as np
  # from copy import deepcopy
  # from collections import deque
  class segtree:
      def __init__(self, n, init_val=0):
          self.n = n
          self.init_val = init_val
          self.init = 0
          self.k = math.ceil(math.log2(n))
          if type(self.init_val) == int:
              self.bins = [init_val] * (1 << (self.k + 1))
          elif len(self.init_val) > 0:
              self.bins = [self.init] * (1 << (self.k + 1))
              for idx, i in enumerate(range(1 << self.k, 1 << (self.k + 1))):
                  if len(self.init_val) > idx:
                      self.bins[i] = init_val[idx]
                  else:
                      self.bins[i] = 0
          else:
              raise ValueError("init_val is invalid.")
          self.caliculate()
  
      def compare(self, l, r):
          return l + r
  
      def caliculate(self):
          k = self.k
          while k:
              for i in range(1 << k, 1 << (k + 1)):
                  if not i % 2:
                      self.bins[i // 2] = self.compare(self.bins[i], self.bins[i + 1])
                  else:
                      continue
              k -= 1
  
      def update(self, idx, val):
          """idx : 0-started index"""
          k = (1 << self.k) + idx
          self.bins[k] = val
          while k > 1:
              self.bins[k // 2] = self.compare(
                  self.bins[k // 2 * 2], self.bins[k // 2 * 2 + 1]
              )
              k = k // 2
  
      def eval(self, l, r):
          ret = self.init
          l = (1 << self.k) + l
          r = (1 << self.k) + r
          # print(l, r)
          while True:
              # print(l, r)
              if r - l == 1:
                  ret = self.compare(ret, self.bins[l])
                  ret = self.compare(ret, self.bins[r])
                  break
              elif l == r:
                  ret = self.compare(ret, self.bins[l])
                  break
              else:
                  done = False
                  if l % 2:
                      ret = self.compare(ret, self.bins[l])
                      l += 1
                      done = True
                  if not r % 2:
                      ret = self.compare(ret, self.bins[r])
                      r -= 1
                      done = True
                  if not done:
                      l = l // 2
                      r = r // 2
          # print(ret)
          return ret
  
      def value(self, ind):
          return self.bins[(1 << self.k) + ind]
  
  
  def run():
      N, K = list(map(int, sysread().split()))
      A = list(map(int, sysread().split()))
      st = segtree(2001, 0)
      T1 = [0] * N
      for i in list(range(N))[::-1]:
          T1[i] = st.eval(0, A[i] - 1)
          st.update(A[i], st.value(A[i]) + 1)
          # print(st.bins)
      T2 = []
      for a in A:
          T2.append(st.eval(0, a - 1))
      ret = 0
      mod = 10**9 + 7
      # print(T1, T2)
      tmp_k2 = K * (K - 1) // 2
      tmp_k2 %= mod
      for t1, t2 in zip(T1, T2):
          ret += K * t1 % mod
          tmp = tmp_k2
          tmp %= mod
          tmp *= t2
          tmp %= mod
          ret += tmp
          ret %= mod
      print(ret)
  
  
  if __name__ == "__main__":
      run()
  
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."}]