N, K = list(map(int, input().split()))

A = list(map(int, input().split()))

mod = 10 ** 9 + 7

table = [0 for _ in range(N)]

ftable = [0 for _ in range(N)]

for i in range(N):

  for j in range(N):

    if A[i] > A[j]:

      table[i] += 1

      if i < j:

        ftable[i] += 1

print(((sum(table) * (K * (K - 1)) // 2 + sum(ftable) * K) % mod))
import sys

input = sys.stdin.readline

N, K = list(map(int, input().split()))

a = list(map(int, input().split()))

mod = 10 ** 9 + 7

class BIT:

  def __init__(self, n):

    self.n = n

    self.data = [0] * (n + 1)

    self.el = [0] * (n + 1)

  def sum(self, i):

    s = 0

    while i > 0:

      s += self.data[i]

      i -= i & -i

    return s

  def add(self, i, x):

    self.el[i] += x

    while i <= self.n:

      self.data[i] += x

      i += i & -i

  def get(self, i, j = None):

    if j is None:

      return self.el[i]

    return self.sum(j) - self.sum(i)



fwk = BIT(2001)

res = 0

for i in range(N):

  res += fwk.get(a[i], 2001)

  res %= mod

  fwk.add(a[i], 1)

res *= K

res %= mod



for i in range(N):

  res += (K * (K - 1) // 2) % mod * fwk.get(a[i], 2001) % mod

  res %= mod

print(res)
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
mod = 10**9 + 7
table = [0 for _ in range(N)]
ftable = [0 for _ in range(N)]
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            table[i] += 1
            if i < j:
                ftable[i] += 1
print(((sum(table) * (K * (K - 1)) // 2 + sum(ftable) * K) % mod))

import sys

input = sys.stdin.readline
N, K = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9 + 7


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)
        self.el = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i

    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)


fwk = BIT(2001)
res = 0
for i in range(N):
    res += fwk.get(a[i], 2001)
    res %= mod
    fwk.add(a[i], 1)
res *= K
res %= mod
for i in range(N):
    res += (K * (K - 1) // 2) % mod * fwk.get(a[i], 2001) % mod
    res %= mod
print(res)

+import sys + +input = sys.stdin.readline -A = list(map(int, input().split())) +a = list(map(int, input().split())) -table = [0 for _ in range(N)] -ftable = [0 for _ in range(N)] + + +class BIT: +    def __init__(self, n): +        self.n = n +        self.data = [0] * (n + 1) +        self.el = [0] * (n + 1) + +    def sum(self, i): +        s = 0 +        while i > 0: +            s += self.data[i] +            i -= i & -i +        return s + +    def add(self, i, x): +        self.el[i] += x +        while i <= self.n: +            self.data[i] += x +            i += i & -i + +    def get(self, i, j=None): +        if j is None: +            return self.el[i] +        return self.sum(j) - self.sum(i) + + +fwk = BIT(2001) +res = 0 -    for j in range(N): -        if A[i] > A[j]: -            table[i] += 1 -            if i < j: -                ftable[i] += 1 -print(((sum(table) * (K * (K - 1)) // 2 + sum(ftable) * K) % mod)) +    res += fwk.get(a[i], 2001) +    res %= mod +    fwk.add(a[i], 1) +res *= K +res %= mod +for i in range(N): +    res += (K * (K - 1) // 2) % mod * fwk.get(a[i], 2001) % mod +    res %= mod +print(res)