# B - Kleene Inversion

from typing import Optional, Sequence





class BinaryIndexedTree:

    """Binary Indexed Tree (Fenwick Tree)

    Each operation runs in O(logN).



    References:

        http://hos.ac/slides/20140319_bit.pdf

    """



    __slots__ = ["_size", "_tree", "is_zero_origin"]



    def __init__(

        self,

        size: int,

        initial_values: Optional[Sequence[int]] = None,

        is_zero_origin: bool = True,

    ):

        self._size = size

        self._tree = [0] * (size + 1)

        self.is_zero_origin = is_zero_origin

        if initial_values:

            self._build(initial_values)



    def _build(self, initial_values: Sequence[int]):

        for i, a in enumerate(initial_values):

            self.add(i, a)



    def add(self, index: int, value: int) -> None:

        """Add value to tree[index], O(logN)."""

        if self.is_zero_origin:

            index += 1

        while index <= self._size:

            self._tree[index] += value

            index += index & -index



    def sum(self, index: int) -> int:

        """Return the sum of [1, index] in O(logN)."""

        ret = 0

        while index > 0:

            ret += self._tree[index]

            index -= index & -index

        return ret



    def range_sum(self, left: int, right: int) -> int:

        """Return the range sum of [left, right] in O(logN)."""

        if not self.is_zero_origin:

            left -= 1

        return self.sum(right) - self.sum(left)





def main():

    N, K, *A = list(map(int, open(0).read().split()))

    tree = BinaryIndexedTree(2000, is_zero_origin=False)

    x = 0

    for i, a in enumerate(A, 1):  # internal inversion

        tree.add(a, 1)

        x += i - tree.sum(a)

    y = -x

    for i, a in enumerate(A, 1):  # external inversion

        tree.add(a, 1)

        y += i + N - tree.sum(a)

    MOD = 10 ** 9 + 7

    print(((x * K + y * K * (K - 1) // 2) % MOD))





if __name__ == "__main__":

    main()

# jsc2019-qualB - Kleene Inversion

class BIT:  # Binary Indexed Tree (Fenwick Tree)

    def __init__(self, lim):

        self.size = lim

        self.tree = [0] * (lim + 1)  # 1-idx



    def add(self, i, x):  # add x to tree[i], O(logN)

        while i <= self.size:

            self.tree[i] += x

            i += i & -i



    def sum(self, i):  # sum of [1, i], O(logN)

        ret = 0

        while i > 0:

            ret += self.tree[i]

            i -= i & -i

        return ret



    def range_sum(self, l, r):  # range sum of [l, r]

        return self.sum(r) - self.sum(l - 1)





def main():

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

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

    MOD = 10 ** 9 + 7

    bit = BIT(2000)

    x = 0

    for i, a in enumerate(A, 1):  # internal inversion

        bit.add(a, 1)

        x += i - bit.sum(a)

    y = -x

    for i, a in enumerate(A, 1):  # external inversion

        bit.add(a, 1)

        y += i + N - bit.sum(a)

    ans = (x * K + y * K * (K - 1) // 2) % MOD

    print(ans)





if __name__ == "__main__":

    main()

# B - Kleene Inversion
from typing import Optional, Sequence


class BinaryIndexedTree:
    """Binary Indexed Tree (Fenwick Tree)
    Each operation runs in O(logN).
    References:
        http://hos.ac/slides/20140319_bit.pdf
    """

    __slots__ = ["_size", "_tree", "is_zero_origin"]

    def __init__(
        self,
        size: int,
        initial_values: Optional[Sequence[int]] = None,
        is_zero_origin: bool = True,
    ):
        self._size = size
        self._tree = [0] * (size + 1)
        self.is_zero_origin = is_zero_origin
        if initial_values:
            self._build(initial_values)

    def _build(self, initial_values: Sequence[int]):
        for i, a in enumerate(initial_values):
            self.add(i, a)

    def add(self, index: int, value: int) -> None:
        """Add value to tree[index], O(logN)."""
        if self.is_zero_origin:
            index += 1
        while index <= self._size:
            self._tree[index] += value
            index += index & -index

    def sum(self, index: int) -> int:
        """Return the sum of [1, index] in O(logN)."""
        ret = 0
        while index > 0:
            ret += self._tree[index]
            index -= index & -index
        return ret

    def range_sum(self, left: int, right: int) -> int:
        """Return the range sum of [left, right] in O(logN)."""
        if not self.is_zero_origin:
            left -= 1
        return self.sum(right) - self.sum(left)


def main():
    N, K, *A = list(map(int, open(0).read().split()))
    tree = BinaryIndexedTree(2000, is_zero_origin=False)
    x = 0
    for i, a in enumerate(A, 1):  # internal inversion
        tree.add(a, 1)
        x += i - tree.sum(a)
    y = -x
    for i, a in enumerate(A, 1):  # external inversion
        tree.add(a, 1)
        y += i + N - tree.sum(a)
    MOD = 10**9 + 7
    print(((x * K + y * K * (K - 1) // 2) % MOD))


if __name__ == "__main__":
    main()

# jsc2019-qualB - Kleene Inversion
class BIT:  # Binary Indexed Tree (Fenwick Tree)
    def __init__(self, lim):
        self.size = lim
        self.tree = [0] * (lim + 1)  # 1-idx

    def add(self, i, x):  # add x to tree[i], O(logN)
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def sum(self, i):  # sum of [1, i], O(logN)
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i & -i
        return ret

    def range_sum(self, l, r):  # range sum of [l, r]
        return self.sum(r) - self.sum(l - 1)


def main():
    N, K = tuple(map(int, input().split()))
    A = tuple(map(int, input().split()))
    MOD = 10**9 + 7
    bit = BIT(2000)
    x = 0
    for i, a in enumerate(A, 1):  # internal inversion
        bit.add(a, 1)
        x += i - bit.sum(a)
    y = -x
    for i, a in enumerate(A, 1):  # external inversion
        bit.add(a, 1)
        y += i + N - bit.sum(a)
    ans = (x * K + y * K * (K - 1) // 2) % MOD
    print(ans)


if __name__ == "__main__":
    main()

-# B - Kleene Inversion -from typing import Optional, Sequence +# jsc2019-qualB - Kleene Inversion +class BIT:  # Binary Indexed Tree (Fenwick Tree) +    def __init__(self, lim): +        self.size = lim +        self.tree = [0] * (lim + 1)  # 1-idx +    def add(self, i, x):  # add x to tree[i], O(logN) +        while i <= self.size: +            self.tree[i] += x +            i += i & -i -class BinaryIndexedTree: -    """Binary Indexed Tree (Fenwick Tree) -    Each operation runs in O(logN). -    References: -        http://hos.ac/slides/20140319_bit.pdf -    """ - -    __slots__ = ["_size", "_tree", "is_zero_origin"] - -    def __init__( -        self, -        size: int, -        initial_values: Optional[Sequence[int]] = None, -        is_zero_origin: bool = True, -    ): -        self._size = size -        self._tree = [0] * (size + 1) -        self.is_zero_origin = is_zero_origin -        if initial_values: -            self._build(initial_values) - -    def _build(self, initial_values: Sequence[int]): -        for i, a in enumerate(initial_values): -            self.add(i, a) - -    def add(self, index: int, value: int) -> None: -        """Add value to tree[index], O(logN).""" -        if self.is_zero_origin: -            index += 1 -        while index <= self._size: -            self._tree[index] += value -            index += index & -index - -    def sum(self, index: int) -> int: -        """Return the sum of [1, index] in O(logN).""" +    def sum(self, i):  # sum of [1, i], O(logN) -        while index > 0: -            ret += self._tree[index] -            index -= index & -index +        while i > 0: +            ret += self.tree[i] +            i -= i & -i -    def range_sum(self, left: int, right: int) -> int: -        """Return the range sum of [left, right] in O(logN).""" -        if not self.is_zero_origin: -            left -= 1 -        return self.sum(right) - self.sum(left) +    def range_sum(self, l, r):  # range sum of [l, r] +        return self.sum(r) - self.sum(l - 1) -    N, K, *A = list(map(int, open(0).read().split())) -    tree = BinaryIndexedTree(2000, is_zero_origin=False) +    N, K = tuple(map(int, input().split())) +    A = tuple(map(int, input().split())) +    MOD = 10**9 + 7 +    bit = BIT(2000) -        tree.add(a, 1) -        x += i - tree.sum(a) +        bit.add(a, 1) +        x += i - bit.sum(a) -        tree.add(a, 1) -        y += i + N - tree.sum(a) -    MOD = 10**9 + 7 -    print(((x * K + y * K * (K - 1) // 2) % MOD)) +        bit.add(a, 1) +        y += i + N - bit.sum(a) +    ans = (x * K + y * K * (K - 1) // 2) % MOD +    print(ans)