Problem:


Score : 300 points

Problem 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.

Constraints

All values in input are integers.

1 \leq N \leq 2000

1 \leq K \leq 10^9

1 \leq A_i \leq 2000

Input

Input is given from Standard Input in the following format:

N K
A_0 A_1 ... A_{N - 1}

Output

Print the inversion number of B, modulo 10^9 + 7.

Sample Input 1

2 2
2 1

Sample Output 1

3

In this case, B~=~2,~1,~2,~1. We have:

B_0 > B_1

B_0 > B_3

B_2 > B_3

Thus, the inversion number of B is 3.

Sample Input 2

3 5
1 1 1

Sample Output 2

0

A may contain multiple occurrences of the same number.

Sample Input 3

10 998244353
10 9 8 7 5 6 3 4 2 1

Sample Output 3

185297239

Be sure to print the output modulo 10^9 + 7.



Sample input:
2 2
2 1


Sample output:
3

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,k = na()
A = na()
mod = 10**9+7

def bSort(a):
    c = 0
    for i in range(len(a)):
        for j in range(len(a)-1, i, -1):
            if a[j] < a[j-1]:
                a[j], a[j-1] = a[j-1], a[j]
                c += 1

    return c

cc = bSort(A)
B = sorted(A)
g = 0
p = 0
for i in range(1,n):
    if B[i-1] != B[i]:
        p+=1
    g += p

j = k*(k-1)//2

ans = cc*k%mod+g*j%mod

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
count1 = 0

for i in range(n):
    for j in range(i+1, len(a)-i):
        if a[i] > a[j]:
            count1 += 1

count2 = 0
for i in range(len(set(a))):
    count2 += i

ans = (count1*k + count2*math.factorial(k-1)) % 1000000007
print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
# スペース区切りの整数の入力
N, K = map(int, input().split())
As = list(map(int, input().split()))

count_base =0
for i in range(N-1):
    for j in range(i+1, N):
        if As[i] > As[j]:
            count_base += 1

count = count_base * (N * K + K *(K-1)/2)

print(count % (pow(10, K) + 7))

Submission status: Wrong Answer

Solution code:
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
Mod = 1000000007




def main(): #startline-------------------------------------------
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    ans = 0
    for i in range(n):
        for j in range(n-1,i,-1):
            if a[j] < a[j-1]:
                a[j],a[j-1] = a[j-1],a[j]
                ans += 1
                ans %= Mod
    p = len(set(a))   
    ans *= k
    for i in range(1,p+1):
        ans += (p-i)*(k*(k-1)//2)
        ans %= Mod
    print(ans)

if __name__ == "__main__":
    main() #endline===============================================





def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n < 2 is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))):
        if prime[i] == 1:
            for j in range(2*i,n):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n):
        if prime[i] == 1:
            res.append(i)
    return res

class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py

    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    A = LIST()
    count = 0
    for i in range(N):
        count_all = 0
        count_ = 0
        for j in range(N):
            if A[i] > A[j]:
                count_all += 1
                if i < j:
                    count_ += 1
        count += count_ * K
        count += count_all * (((K - 1) % mod) * (K % mod) % mod) / 2
        # import pdb; pdb.set_trace()
    print(int(count) % mod)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
alist=[int(i) for i in input().split()]
blist=alist+alist
counta=0
countb=0
for i in range(n):
	for j in range(i+1,n):
		if alist[i] > alist[j]:
			counta+=1
for i in range(n*2):
	for j in range(i+1,n*2):
		if blist[i] > blist[j]:
			countb+=1
minus=countb-counta
print((counta+(k*(k-1)//2)*minus)%(10**9+7))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
aa = list(map(int, input().split()))

mod = 10**9+7

ans = 0

s = 0
count = [0 for _ in range(2000)]
for a in aa :
    s += sum(count[a:])
    count[a-1] += 1
ans = s*k%mod

s = 0
for i in range(2000) :
    s += sum(count[i+1:])
ans = (ans+s*k*(k-1)//2)%mod

print(ans)

Submission status: Wrong Answer

Solution code:
n,k=input().split(" ")
n=int(n)
k=int(k)
s=input()
li=s.split(" ")


ans=1
for i in range(len(li)-1):
    if li[i]!=li[i+1]:
        ans+=1
print(pow(ans,k)-1)

Submission status: Wrong Answer

Solution code:
#######################################
prime = 10**9+7

def sowa(num):
  return int((1+num)*num/2)
#######################################
n,k = map(int, input().split())
a = list(map(int, input().split()))


tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = sum(tento1) *(k%prime) %prime + sum(tento2) *(sowa(k-1) %prime)%prime
print(ret%prime)

Submission status: Wrong Answer

Solution code:
import sys
from math import factorial

MOD = 1000000007

input = sys.stdin.readline

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

k %= MOD
fact_k = factorial(k - 1) % MOD

a1 = [0] * n
a2 = [0] * n

for i, ai in enumerate(a):
    for j in range(n):
        if ai > a[j]:
            a1[i] += 1
            if j > i:
                a2[i] += 1

ans = 0
for ai in a2:
    ans += ai * k % MOD

for ai in a1:
    ans += ai * fact_k % MOD

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
def add(a, b):
  return (a + b) % MOD
def sub(a, b):
  return (a - b) % MOD
def mul(a, b):
  return ((a % MOD) * (b % MOD)) % MOD
def div(a, b):
  return ( (a % MOD) * (power(b, MOD)) ) % MOD
def power(a, b):
  return pow(a, b, MOD)


n, k = map(int, input().split())
an = list(map(int, input().split()))
n1 = [0] * n
n2 = [0] * n
for i, v in enumerate(an):
  n1[i] = len([x for x in an[i+1:] if x < v])
  n2[i] = n1[i] + len([x for x in an[:i] if x < v])

cnt = 0
ks = mul(k-1, k) // 2
for i in range(n):
  cnt = add(cnt, mul(n1[i], k))
  cnt = add(cnt, mul(n2[i], ks))
print(cnt)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n,k = m()

a = l()

aaa = [0 for i in range(n)]
co = [0 for i in range(2002)]


for i in range(n-1,-1,-1):
    aaa[i] = co[a[i]]
    for j in range(a[i]+1,n+1):
        co[j] += 1


su = 0

for i in range(n):
    su += k * aaa[i]
    su %= mod
    if k != 1:
        su += ((k)*(k-1)//2)*co[a[i]]
    su %= mod


print(su)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

x = 0
for l in range(N - 1):
  for r in range(l + 1, N):
    if A[l] > A[r]:
      x += 1
# print(x)
      
AA = A + A
y = 0
for l in range(2 * N - 1):
  for r in range(l + 1, 2 * N):
    if AA[l] > AA[r]:
      y += 1
y -= 2 * x
# print(y)

# print(int((K * x + K * (K - 1) * y / 2) % (10 ** 9 + 7)))
print(int((K * x  % (10 ** 9 + 7) + K * (K - 1) * y / 2  % (10 ** 9 + 7)) % (10 ** 9 + 7)))

Submission status: Wrong Answer

Solution code:
def count_inversion(sequence):
  return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))

n,k=map(int,input().split())

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

j=0
for i in range(k+1):
  #print(i)
  j+=i

#print(count_inversion(r))
  
print((count_inversion(r)*j)%(10**9+7))

Submission status: Wrong Answer

Solution code:
def main():
    n, k = map(int, input().split(" "))
    A = list(map(int, input().split(" ")))

    Anomitenti = 0
    ikotonaritenti = 0
    for index, i in enumerate(A):
        for j in A[index+1:]:
            if i > j:
                Anomitenti+= 1
        for j in A:
            if i > j:
                ikotonaritenti += 1

    kosuu = int(1 + (k-1) * k / 2)
    result = Anomitenti * k + ikotonaritenti * kosuu
    print(result % 1000000007)

main()

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7
n, k = [ int(v) for v in input().split() ]

num_list = [ int(v) for v in input().split() ]
num_list_2 = [ i - 1 for i in num_list ]
t_list = []
for i, v in enumerate(num_list):
    t = 0
    for j in range(i+1,n):
        if num_list[j] < v:
            t += 1
    t_list.append(t)


a = ( k * (k-1) )  // 2
a = a % mod

print( (sum(num_list_2)*a+ k*sum(t_list) ) % mod)

Submission status: Wrong Answer

Solution code:
N,K=(int(x) for x in input().split())
A=list(map(int,input().split()))
junretu=0
sougou=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            junretu+=1
            junretu=junretu%1000000007
for i in range(N):
    for j in range(N):
        if A[i]>A[j]:
            sougou+=1
            sougou=sougou%1000000007
ans=((K*junretu%1000000007)+(sougou*K*(K-1)/2)%1000000007)%1000000007
print(round(ans))

Submission status: Wrong Answer

Solution code:
n,m=map(int,input().split())
hoge=list(map(int,input().split()))
ans=0
for i in range(len(hoge)):
  huga=[j for j in hoge if j<hoge[i]]
  ans+=(len(huga)*int(m*(m+1)/2))
  ans=ans%(10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

N, K = getlist()
A = getlist()

x = 0
for i in range(N):
	for j in range(i + 1, N):
		if A[i] > A[j]:
			x += 1

B = sorted(A)
s = 0
v = 0
c = 0
for i in range(N):
	if B[i] > v:
		c = i
	s += c
	v = B[i]


ans = int(((K - 1) * K) / 2) * s + K * x
print(ans % 1000000007)

Submission status: Wrong Answer

Solution code:
n ,k  = map(int,input().split())
a =input().split()
a_re = a * n

count = 0

for i in range(len(a_re)):
    for j in range(len(a_re)):
        if i !=j and a_re[i] > a_re[j]and i <= j:
            print(a_re[i] , a_re[j])
            count +=1
ans = count % (10**9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
inf = 10**9 + 7

tmp = 0
for i in range(0, N-1):
    for j in range(i+1, N):
        if A[i] > A[j]:
            tmp += 1

#print(tmp )

tmp%= inf

ans = (K+1)*K//2 % inf
ans = ans * tmp  
ans %= inf

#print(ans)


x = len(list(set(A)))


a = tmp * K % inf
b = (x*(x-1)//2) % inf
c = (K*(K-1)//2) % inf
d = a + b * c
e = d% inf
print(e)

Submission status: Wrong Answer

Solution code:
import bisect

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

mod = 10**9 + 7

reverse = 0
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            reverse += 1

ans = reverse * k % mod

if k == 1:
    print(ans)
else:
    k -= 1
    a.sort()
    m = n
    for ai in a:
        i = bisect.bisect_right(a, ai)
        count = n - i
        ans += count * k * (k+1) // 2 % mod
        ans %= mod

print(ans)

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
lis_a = list(map(int, input().split()))
lis_a.sort(reverse=True)
mod = 1000000007
ans = 0
temp = 0
for i in range(len(lis_a)):
    for j in range(len(lis_a)):
        if(lis_a[i] > lis_a[j]):
            temp += 1
for i in range(1,k+1):
        ans = (ans + temp*i) % mod
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n, k = map(int, input().split())
a = list(map(int, input().split()))
count1 = 0

for i in range(n):
    for j in range(i+1, len(a)-i):
        if a[i] > a[j]:
            count1 += 1

count2 = 0
for i in range(len(set(a))):
    count2 += i

ans = count1*k + count2*math.factorial(k-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n,k=map(int, input().split())
a=list(map(int, input().split()))
b=Counter(a)
count=0
now=0
for i in sorted(b):
    count+=now
    now+=b[i]
count*=(k-1)*k//2
c=[]
count2=0
import bisect
for i in a[::-1]:
    count2+=bisect.bisect_left(c,i)
    bisect.insort(c, i)
count2*=k
print((count+count2)%(10**9+7))

Submission status: Wrong Answer

Solution code:
n ,k  = map(int,input().split())
a =input().split()
a_re = a * n
print(a_re)

count = 0

for i in range(len(a_re)):
    for j in range(len(a_re)):
        if i !=j and a_re[i] > a_re[j]and i <= j:
            count +=1
ans = count % (10**9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_2 = a.copy()
a_2.extend(a)

lst_1 = [0 for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            lst_1[i] += 1

lst_2 = [0 for i in range(n)]
for i in range(n):
    for j in range(i+1, 2*n):
        if a[i] > a_2[j]:
            lst_2[i] += 1

arr1 = np.array(lst_1)
arr2 = np.array(lst_2)
arr2 = arr2 - arr1
sum1 = sum(arr1)
sum2 = sum(arr2)
ans = ((sum1*k) % (10**9+7) + ((((sum2 * (k-1)) % (10**9+7)) * k) % (10**9+7)) // 2) % (10**9+7)

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
mod=10**9+7
b=0
f=0
for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            #print(A[i],",",A[j])
            f+=1
           
            
for i in range(N-1,-1,-1):
    for j in range(i-1,-1,-1):
        if A[i]>A[j]:
            b+=1
tmp=(K+1)*K%mod
ans=(f*tmp/2)%mod
tmp=(K-1)*K%mod
ans+=(b*tmp/2)%mod
ans%=mod
print(int(ans))

Submission status: Wrong Answer

Solution code:
import collections

def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt
if __name__ == "__main__":
    N,K = map(int,input().split())
    Len = N
    A = list(map(int,input().split()))
    num = 10 ** 9 + 7
    ti = (K * (K -1) / 2)%num
    count = 0
    cnt = bubble_sort(A)
    count = (count +cnt*K) % num
    C = collections.Counter(A)
    c = sorted(C.items(),key=lambda x:x[1],reverse = True)
    for a in c:
        b = a[1]
        Len -= b
        for i in range(b):
            count = (count +Len * ti) % num
    print(int(count))

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int,input().split())
a = input().split()

cnt = 0
for i in range(0,len(a)-1):
    for j in range(i+1,len(a)):
        cnt += (a[i] > a[j])

ed = 10**9+7

ans = cnt*math.factorial(k)
print(ans%ed)

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    mod = 10**9+7
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            if arr[i] > arr[j]:
                ans += 1

    ans = ans*k
    ans = ans%mod

    dist = {}
    for i in arr:
        if i not in dist.keys():
            dist[i] = 1
        else:
            dist[i] += 1

    arr = []
    for i in dist.keys():
        arr.append((i,dist[i]))

    arr.sort(reverse = True)
    count = 0
    total = 0
    for i in arr:
        total += i[1]

    for i in arr:
        total -= i[1]
        count += total

    count = count*k*(k-1)//2
    count = count%mod
    ans += count
    print(ans%mod)
    


main()

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    A = LIST()
    count = 0
    for i in range(N):
        count_all = 0
        count_ = 0
        for j in range(N):
            if A[i] > A[j]:
                count_all += 1
                if i < j:
                    count_ += 1
        count += count_ * K
        count += count_all * (K - 1) * K / 2
        count = count % mod
    print(int(count) % mod)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = 0
outer = 0
for i in range(0,n):
    for j in range(0,n):
        if a[i] > a[j]:
            outer += 1
            if i < j:
                inner += 1

print(int((inner * k + outer * k * (k-1) / 2) % 1000000007))

Submission status: Wrong Answer

Solution code:
import collections

def bubble_sort(A):
    cnt = 0
    for i in range(len(A)):
        for j in range(len(A)-1, i, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                cnt += 1
    return cnt
if __name__ == "__main__":
    N,K = map(int,input().split())
    Len = N
    A = list(map(int,input().split()))
    num = 10 ** 9 + 7
    ti = (K * (K -1) / 2)%num
    count = 0
    cnt = bubble_sort(A)
    count += cnt*K % num
    C = collections.Counter(A)
    c = sorted(C.items(),key=lambda x:x[1],reverse = True)
    for a in c:
        b = a[1]
        Len -= b
        for i in range(b):
            count = (count +Len * ti) % num
    print(int(count))

Submission status: Wrong Answer

Solution code:
#######################################
prime = 10**9+7

def sowa(num):
  return int((1+num)*num/2)
#######################################
n,k = map(int, input().split())
a = list(map(int, input().split()))


tento1 = [sum([1 if a[i]>a[j] else 0 for j in range(i+1,n)]) for i in range(n-1)]
tento2 = [sum([1 if a[i]>a[j] else 0 for j in range(n)]) for i in range(n)]


ret = sum(tento1) *k %prime + sum(tento2) *sowa(k-1) %prime
print(ret%prime)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

MOD = (10 ** 9) + 7

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if(A[i] > A[j]):
            ans = (ans +  (K * (K+1) // 2)) % MOD

print(ans % MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_2 = a.copy()
a_2.extend(a)

lst_1 = [0 for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            lst_1[i] += 1

lst_2 = [0 for i in range(n)]
for i in range(n):
    for j in range(i+1, 2*n):
        if a[i] > a_2[j]:
            lst_2[i] += 1

arr1 = np.array(lst_1)
arr2 = np.array(lst_2)
arr2 = arr2 - arr1
sum1 = sum(arr1)
sum2 = sum(arr2)
ans = ((sum1*k) % (10**9+7) + ((sum2 * (k-1)) % (10**9+7)) * k // 2) % (10**9+7)

print(ans)

Submission status: Wrong Answer

Solution code:
N,K=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]


inside=0
for i in range(N):
    for j in range(i,N):
        if A[i]>A[j]:
            inside+=1

outside=0
for i in range(N):
    for j in range(N):
        if A[i]>A[j]:
            outside+=1

print(inside,outside)

s=inside*K+outside*((K*(K-1))//2)

print(s%(10**9+7))

Submission status: Wrong Answer

Solution code:
import math

n, k = map(int,input().split())
a = input().split()

cnt = 0
for i in range(0,len(a)-1):
    for j in range(i+1,len(a)):
        cnt += (a[i] > a[j])

ed = 10**9+7

ans = cnt*math.factorial(k)
print(ans//ed)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
alist = list(map(int, input().split()))

mlist=[0]*n
nlist=[0]*n

for i in range(n):
    for j in range(n):
        if alist[i]>alist[j] and i>j:
            mlist[i]+=1
        elif alist[i]>alist[j] and i<j:
            nlist[i]+=1

#print(mlist, nlist)
kotae=0
for i in range(n):
    kotae+=int(nlist[i]*k*(k+1)/2)%(10**9+7)
    kotae+=int(mlist[i]*(k)*(k-1)/2)%(10**9+7)

print(kotae%(10**9+7))

Submission status: Wrong Answer

Solution code:
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N, K = MAP()
    A = LIST()
    count = 0
    for i in range(N):
        count_all = 0
        count_ = 0
        for j in range(N):
            if A[i] > A[j]:
                count_all += 1
                if i < j:
                    count_ += 1
        count += count_ * K
        count += count_all * (K - 1) * K / 2
    print(int(count) % mod)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n,k = m()

a = l()

aaa = [0 for i in range(n)]
co = [0 for i in range(2002)]


for i in range(n-1,-1,-1):
    aaa[i] = co[a[i]]
    for j in range(a[i]+1,n+1):
        co[j] += 1


su = 0

for i in range(n):
    su += k * aaa[i]
    su %= mod
    su += ((k)*(k-1)//2)*co[a[i]]
    su %= mod


print(su)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

a_2 = a.copy()
a_2.extend(a)

lst_1 = [0 for i in range(n)]
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            lst_1[i] += 1

lst_2 = [0 for i in range(n)]
for i in range(n):
    for j in range(i+1, 2*n):
        if a[i] > a_2[j]:
            lst_2[i] += 1

arr1 = np.array(lst_1)
arr2 = np.array(lst_2)
arr2 = arr2 - arr1
sum1 = sum(arr1)
sum2 = sum(arr2)
ans = (sum1*k + ((sum2 * (k-1)) % (10**9+7)) * k // 2) % (10**9+7)

print(ans)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7

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

incount = 0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i] > a[j]:
            incount += 1

print(incount)

out = 0

for p in range(n):
    for q in range(n):
        if a[p] < a[q]:
            out += 1

print(out)

outcount = out * (k * (k-1)) //2

print((incount * k + outcount) % MOD)

Submission status: Wrong Answer

Solution code:
import numpy as np

MOD = 1000000007
N, K = map(int, input().split())
Alist = np.array(list(map(int, input().split())))

ans = 0
for i in range(N):
    l = Alist[:i]
    r = Alist[i+1:]
    ans += (sum(l < Alist[i]) * int(K*(K-1)/2)) % MOD
    ans += (sum(r < Alist[i]) * int(K*(K+1)/2)) % MOD
    ans = ans % MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

x = 0
for i in range(n):
    for j in range(i+1, n):
        if a[i] > a[j]:
            x += 1

y = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            y += 1

mod = 10**9 + 7
ans1 = (x*k) % mod
ans2 = ((k*(k-1)*y) / 2) % mod
print((ans1 + int(ans2)) % mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
N,K=map(int,input().split())
A=list(map(int,input().split()))

a0=0
a1=0

for i in range(N):
    for j in range(i+1,N):
        if A[i]>A[j]:
            a0+=1
for i in range(N):
    for j in range(N):
        if A[i]>A[j]:
            a1+=1
#print(a0)   
#print(a1)
print(int(a0*K+a1*(K-1)*K/2)%mod)

Submission status: Wrong Answer

Solution code:
n ,k  = map(int,input().split())
a =[list(map(int,input().split()))]

def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))
  
sample = count_inversion(a)
print(sample)
ans = sample % (10**9 + 7)

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n,k = map(int,input().split())
    arr = list(map(int,input().split()))
    mod = 10**9+7
    ans = 0
    for i in range(n):
        for j in range(i+1,n):
            if arr[i] > arr[j]:
                ans += 1

    ans = ans*k
    ans = ans%mod

    dist = set()
    for i in arr:
        if i not in dist:
            dist.add(i)

    n = len(dist)
    count = k*(k-1)//2
    count = count%mod
    count = count*n*(n-1)//2
    count = count%mod
    ans += count
    print(ans%mod)
    


main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

flip_N = 0
flip_global = 0

mod = 1000000007

for i in range(N):
    for j in range(N):
        if (i == j):
            continue
        if (A[i] > A[j]):
            flip_global += 1

            if (i < j):
                flip_N += 1

comb = int(K * (K-1) / 2)

print(int((flip_N * K + flip_global * comb) % mod))

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

inf = 1000000007
ans = 0
for i in range(N):
    cnt1 = cnt2 = 0
    for j in range(i):
        if A[j] < A[i]:
            cnt1 += 1
    for j in range(i,N):
        if A[j] < A[i]:
            cnt2 += 1
    ans += int((K*(K+1)/2)*cnt2+((K-1)*K/2)*cnt1)
    ans %= inf

print(ans)

Submission status: Wrong Answer

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n,k = m()

a = l()

aaa = [0 for i in range(n)]
co = [0 for i in range(2002)]


for i in range(n-1,-1,-1):
    aaa[i] = co[a[i]]
    for j in range(a[i]+1,n+1):
        co[j] += 1


su = 0

for i in range(n):
    su += k * aaa[i] + ((k)*(k-1)//2)*co[a[i]]
    su %= mod


print(su)

Submission status: Wrong Answer

Solution code:
import sys, math, itertools, bisect, copy, re

from collections import Counter, deque, defaultdict
from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
from functools import reduce
from math import ceil, floor, log10, log2, factorial
from pprint import pprint

# 10倍速いらしい
input = sys.stdin.readline

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

T1 = [0] * N
T2 = [0] * N

for i in range(N - 1):
    for j in range(i + 1, N):
        if A[i] > A[j]:
            T1[i] += 1
    for j in range(0, N):
        if A[i] > A[j]:
            T2[i] += 1

ans = sum(T1) * K
ans %= MOD
ans += sum(T2) * K * (K - 1) // 2
ans %= MOD

print(ans)
# print(T1)
# print(T2)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))

MOD = 10**9+7

ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans += 1
ans *= K

from collections import Counter
ctr = Counter(A)

P = (K*(K-1)//2) % MOD

s = 0
for k,v in sorted(ctr.items()):
    tmp = (s*P)%MOD
    ans += tmp
    ans %= MOD
    s += v

print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = input().split()

cnt = 0
for i in range(0,len(a)-1):
    for j in range(i+1,len(a)):
        cnt += (a[i] > a[j])

ed = 10**9+7

ans = 1
for i in range(k,1,-1):
    ans += i*cnt 
print(ans//ed)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split())
a = input().split()

cnt = 0
for i in range(0,len(a)-1):
    for j in range(i+1,len(a)):
        cnt += (a[i] > a[j])
        
ans = 1
for i in range(k,1,-1):
    ans += i*cnt 
print(ans)