# frozen_string_literal: true

n, k = gets.split(' ').map(&:to_i)
array = gets.split(' ').map(&:to_i)

def calc_inv_with_inv_table arr
  bits = arr.size.to_s(2).size
  inv = 0
  r = 1 << bits
  a_size = 1
  (bits-1).downto(0) do |i|
    a = Array.new(a_size){0}
    arr.each do |n|
      if n[i].zero?
        inv += a[n.div(r)]
      else
        a[n.div(r)] += 1
      end
    end
    r >>= 1
    a_size <<= 1
  end
  inv
end

k.times do |i|
  next if i == 0

  array.concat array
end

count = calc_inv_with_inv_table(array)
puts count % (1000000000 + 7)

