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:
N,K=map(int,input().split())

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

d=10**9+7

c=0

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

A=list(set(A))

l=len(A)

cc=l*(l-1)/2

e=(K*(K-1)/2)%d

print(int(((c*K)%d+(cc*e)%d)%d))

Submission status: Wrong Answer

Solution code:
import sys
N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

mod=10**9+7

naka=[ 0 for _ in range(N)]
soto=[ 0 for _ in range(N)]

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

A.sort()

for i in range(N-1):
	if A[i]<A[i+1]:
		soto[i+1]=i+1


print (sum(naka)*K+sum(soto)*K*(K-1)/2)%mod

Submission status: Wrong Answer

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

ans = 0
# 単調減少
for i in range(n-1):
    b = a[i]
    count = 0
    for j in range(i+1, n):
        if b > a[j]:
            count += 1
    ap = int(k * (k+1) / 2)% MOD
    tmp = (count * ap) % MOD
    ans += tmp
    ans %= MOD

# それ以外
for i in range(1, n):
    b = a[i]
    count = 0
    for j in range(i):
        if b > a[j]:
            count += 1
    ap = int((k-1) * k / 2)% MOD
    tmp = (count * ap) % MOD
    ans += tmp
    ans %= MOD
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def modInverse(a,m):
    m0 = m 
    y = 0
    x = 1
  
    if (m == 1) : 
        return 0
  
    while (a > 1) : 
        q = a // m 
        t = m 
        m = a % m 
        a = t 
        t = y 
        y = x - q * y 
        x = t 
  
    if (x < 0) : 
        x = x + m0 
  
    return x 

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)
    count = count%mod
    count = count*modInverse(2,mod)
    count = count%mod
    ans += count
    print(ans%mod)
    


main()

Submission status: Wrong Answer

Solution code:
import math

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

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

print((count * math.factorial(K - 1) + count * K) % (10 **9 + 7))

Submission status: Wrong Answer

Solution code:
n,k=[int(i) for i in input().split()]
a_list=[int(s) for s in input().split()]

mod=10**9+7

# 単体の転倒数
first=0
for i in range(n-1):
    a=a_list[i]
    for j in range(i+1,n):
        if a>a_list[j]:
            first+=1

# 右に同じ列があったときの転倒数
a_num=len(set(a_list))
rightnum=a_num*(a_num-1)//2

ans=0
samecol=(k*(k-1)//2)%mod
ans=(ans+samecol*rightnum)%mod
ans=(ans+first*k)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
num = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            num[i][1] += 1
        if (i < j) and (a[i] > a[j]):
            num[i][0] += 1
num_np = np.array(num)
ks = (k * (k - 1) / 2)  % 1000000007
sum_left = sum(num_np[:,0])
sum_right = sum(num_np[:,1])
output = (sum_left * k) % 1000000007 + (sum_right * ks) % 1000000007
print(int(output % 1000000007))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A=list(map(int,input().split()))
A_sort=sorted(A)
Mod=10**9+7
ans_first=0
ans_sec=0
for i in range(len(A)):
  for j in range(i+1,len(A)):
    if A[i]>A[j]:
      ans_first+=1
for i in A:
  for j in A:
    if i > j:
      ans_sec+=1
K%=Mod
tmp=(2*ans_first+(K-1)*ans_sec)%Mod
ans=(tmp*K//2)%Mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7


def LI():
    return list(map(int, sys.stdin.readline().split()))


def II():
    return int(sys.stdin.readline())


def LS():
    return list(map(list, sys.stdin.readline().split()))


def S():
    return sys.stdin.readline()[:-1]


def main():
    n, k = LI()
    a_s = LI()
    ts = [0 for i in range(n)]
    f_ts = [0 for i in range(n)]
    for i in range(n):
        for j in range(n):
            if a_s[j] < a_s[i]:
                ts[i] += 1
                if j > i:
                    f_ts[i] += 1
    sum_f = sum(f_ts)
    sum_ = sum(ts)
    ans = (2 * (sum_f) + sum_ * (k - 1)) * k / 2 % MOD
    print(int(ans))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, k = [float(i) for i in input().split()]
As = [int(i) for i in input().split()]

init = []
aft = []
for i in range(len(As)):
  initmp = 0
  afttmp = 0
  for j in range(len(As)):
    if i > j and As[i] < As[j]:
      initmp += 1
      afttmp += 1
    elif As[i] < As[j]:
      afttmp += 1
  init.append(initmp)
  aft.append(afttmp)

ans = 0
for i, a in zip(init, aft):
  ans += 0.5 * (k * (2 * i + (k-1) * a))
print(int(ans % float((10**9)+7)))

Submission status: Wrong Answer

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

counter = 0
flag = 1
while flag:
    index = 0
    flag = 0
    while index < len(listA)-1:
        if listA[index] > listA[index+1]:
            listA[index], listA[index+1] = listA[index+1], listA[index]
            flag = 1
            counter+=1
        index+=1

listV = []
listK = []
index = 0
bef = ""
count = 0
while index < len(listA):
    if bef == "":
        count = 1
        bef = listA[index]
    elif listA[index] == bef:
        count+=1
    else:
        listV.append(bef)
        listK.append(count)
        bef = listA[index]
        count = 1
    index+=1
listV.append(bef)
listK.append(count)
listS = [0]
index=0
while index < len(listK)-1:
    listS.append(listS[index]+listK[index+1])
    index+=1
sumS = sum(listS)
index3 = 1
sumX = k*(k-1)//2
print((sumS*sumX+counter*(k))%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!




bef=input().rstrip().split(" ")
bef[0]=int(bef[0])
bef[1]=int(bef[1])
ans=0
spin=0

between=0;
data=input().rstrip().split(" ")
for i in range(bef[0]):
    data[i]=int(data[i])
    #if not i==0:
     #   if data[i-1]> data[i]:
      #      spin=spin+1
for i in range(bef[0]):
    for j in range(bef[0]):
        if data[i] >data[j]:
            spin=spin+1
        if data[i]< data[j]:
            between=between+1
ans=(between*(bef[1] - 1) + spin*bef[1] )%1000000007
print(ans)
#print(between)
#print(spin)

Submission status: Wrong Answer

Solution code:

import sys
sys.setrecursionlimit(10**6)
##############################

import math

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

A = ''.join(input().split()) * 2
a = list(A)

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

if count == 0 or K <= 2:
    print(count)
    exit()

z = K-2
count = count * (math.factorial(z-1))
print(count)

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())
a=list(map(int,input().split()))
ans=[]
for i in range(k):
    ans+=a
print(ans)


print(count_inversion(ans))

Submission status: Wrong Answer

Solution code:
nk = input().split(" ");
n = int(nk[0]);
k = int(nk[1]);
a = input().split(" ");

waru = 10 ** 9 + 7;

for i in range(n) :
	a[i] = int(a[i]);

kaisu = [0] * n;
usiro = [0] * n;

for i in range(n) :
	for j in range(n) :
		if a[i] > a[j] :
			kaisu[i] += 1;
			if i < j :
				usiro[i] += 1;

ans = 0;
for i in range(n) :
	ans += (k-1)*k * kaisu[i]/2 + usiro[i] *k
		
	
print(int(ans%waru));

Submission status: Wrong Answer

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

if n==1:
  print(0)
else:
  for i in range(n-1):
    for j in range(n-i):
      if a[i] > a[i+j]:
        count1 += 1

  for i in range(n-1):
    if a[n-1] > a[i]:
      count2 += 1

  len1 = sum(range(1,k+1))
  len2 = sum(range(1,k))

  print( ((len1*count1) + (len2*count2)) % (10**9 + 7))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
#input = sys.stdin.readline

def solve():
  n,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  mod = 10**9+7
  firstt = [0]*n
  for i in range(n-1):
    for j in range(i+1,n):
     if a[i] > a[j]:
      firstt[i] += 1
      
  secondt = [0]*n
  a2 =  a + a
  for i in range(n):
   for j in range(i+1,2*n):
    if a2[i] > a2[j]:
      secondt[i] += 1
  
  query = []
  for i in range(n):
    query.append(secondt[i]-2*firstt[i])

  ans = 0
  for i in range(n):
    
    ans += 0.5*(query[i]*(k*(k-1)%mod))
    ans += 0.5*(firstt[i]*(k*(k+1)%mod))
  print(int(ans%mod))
solve()

Submission status: Wrong Answer

Solution code:
A = list(map(int, input().split()))
B = list(map(int, input().split()))
 
N = A[0]
K = A[1]
count = 0
 
list = []
 
for i in range(N):
  for j in range(i,N):
    if B[i] > B[j]:
      count+=1
 
count = count*K
  
count = count%(10**9 + 7)
print(count)

Submission status: Wrong Answer

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

#　そのブロック内での転倒数
ans1 = 0
for i in range(N):
    for j in range(i+1,N):
        if A[i] > A[j]:
            ans1 += 1

#　２つのブロック内での転倒数
ans2 = 0
B = sorted(A)
now = B[0]
cnt = 0
for i in range(1,N):
    if now != B[i]:
        cnt = i
        ans2 += cnt
        now = B[i]
    else:
        ans2 += cnt

ans11 = ans1 * K
ans22 = ans2 * (K * (K-1) / 2)
ans = ans11 + ans22
print(int(ans) % MOD)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import collections


def input():
    return sys.stdin.readline()[:-1]


def main():
    N, K = map(int, input().split())
    A = [int(i) for i in input().split()]
    mod = 10**9+7
    ans = 0
    count = 0
    c = collections.Counter(A)
    k = list(c.keys())
    k.sort(reverse=True)

    # print(c)
    s = c[k[0]]
    for i in k[1:]:
        count += s
        s += c[i]

    for i, v in enumerate(A):
        for j in range(0, i):
            if A[j] > v:
                ans += 1
    # print(ans, count)

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7


def LI():
    return list(map(int, sys.stdin.readline().split()))


def II():
    return int(sys.stdin.readline())


def LS():
    return list(map(list, sys.stdin.readline().split()))


def S():
    return sys.stdin.readline()[:-1]


def main():
    n, k = LI()
    a_s = LI()
    ts = [0 for i in range(n)]
    f_ts = [0 for i in range(n)]
    for i in range(n):
        for j in range(n):
            if a_s[j] < a_s[i]:
                ts[i] += 1
                if j > i:
                    f_ts[i] += 1
    sum_f = sum(f_ts)
    sum_ = sum(ts)
    print(f_ts, sum_f)
    print(ts, sum_)
    ans = (2 * (sum_f) + sum_ * (k - 1)) * k / 2 % MOD
    print(int(ans))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split(' ')]
arr = [int(x) for x in input().split(' ')]
arr = arr

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 K == 1:
  print(bubble_sort(arr) % (10**9 + 7))
else:
  arr2 = arr * 2
  cnt_1 = bubble_sort(arr)
  cnt_2 = bubble_sort(arr2)
  sabun = cnt_2 - cnt_1*2
  
  sabun_sum = (K -1) * K * 0.5 * sabun
  
  print(int((cnt_1 * K + sabun_sum) % (10**9 + 7)))

Submission status: Wrong Answer

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

counter = 0
flag = 1
while flag:
    index = 0
    flag = 0
    while index < len(listA)-1:
        if listA[index] > listA[index+1]:
            listA[index], listA[index+1] = listA[index+1], listA[index]
            flag = 1
            counter+=1
        index+=1

listV = []
listK = []
index = 0
bef = ""
count = 0
while index < len(listA):
    if bef == "":
        count = 1
        bef = listA[index]
    elif listA[index] == bef:
        count+=1
    else:
        listV.append(bef)
        listK.append(count)
        bef = listA[index]
        count = 1
    index+=1
listV.append(bef)
listK.append(count)
print(listK)
listS = [0]
index=0
while index < len(listK)-1:
    listS.append(listS[index]+listK[index+1])
    index+=1
sumS = sum(listS)
index3 = 1
sumX = k*(k-1)//2
print((sumS*sumX+counter*(k))%(10**9+7))

Submission status: Wrong Answer

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

tento = [0]*len(A)
rev_tento = [0]*len(A)
for i, ai in enumerate(A):
    for j, aj in enumerate(A[i+1:]):
        if ai>aj: tento[i] += 1
        elif ai<aj: rev_tento[i+j+1] += 1

ans = 0
for t, r in zip(tento, rev_tento):
    #print('t, r:', t, r)
    ans += t*(K+K**2-int((K+1)*K/2))
    ans = ans%div
    ans += r*(K**2-int((K+1)*K/2))
    ans = ans%div
    #print(' ans:', ans)

print(ans)

Submission status: Wrong Answer

Solution code:
MAX = 10**9 + 7

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

total = 0
for i in range(N):
    total += int(len(list(filter(lambda x: x < A[i], A))) * K * (K+1) / 2) - len(list(filter(lambda x: x < A[i], A[:i]))) * K
    # print(i, A[i], int(len(list(filter(lambda x: x < A[i], A))) * K * (K+1) / 2), len(list(filter(lambda x: x < A[i], A[:i]))) * K)
    total %= MAX

print(total)

Submission status: Wrong Answer

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

count = 0
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
        if la[i] > la[jj]:
            count += 1

num = len(set(la)) - 1
result = (count*k) + ((1/2)*(num)*(num+1))*((1/2)*(k-1)*(k))
print(int(result%(pow(10,9)+7)))

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 * (K + K *(K-1)/2)

print(int(count % (pow(10, 9) + 7)))

Submission status: Wrong Answer

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

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

x=10**9+7

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

ans=0
for i in range(1,k+1):
  ans+=(a*i)%x
  
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(100000000)
#input = sys.stdin.readline

def solve():
  n,k = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  mod = 10**9+7
  firstt = [0]*n
  for i in range(n-1):
    for j in range(i+1,n):
     if a[i] > a[j]:
      firstt[i] += 1
      
  secondt = [0]*n
  a2 =  a + a
  for i in range(n):
   for j in range(i+1,2*n):
    if a2[i] > a2[j]:
      secondt[i] += 1
  
  query = []
  for i in range(n):
    query.append(secondt[i]-2*firstt[i])

  ans = 0
  for i in range(n):
    
    ans += 0.5*(query[i]*(k*(k-1)%mod))
    ans += 0.5*(firstt[i]*(k*(k+1)%mod))
    ans %= mod
  print(int(ans%mod))
solve()

Submission status: Wrong Answer

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

def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt

B=A*2
a1=mergecount(A)
a2=mergecount(B)-2*a1

print((a1*K+int(a2*K*(K-1)/2)) % (10**9+7))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
  print("0")
  exit()
ans_unit = 0
for i in range(n-1):
  for j in range(i+1, n):
    if a[i] > a[j]:
      ans_unit+=1
if k == 1:
  print(ans_unit)
  exit()
c = sum([a,a], [])
ans_two = 0
for i in range(2*n-1):
  for j in range(i+1, 2*n):
    if c[i] > c[j]:
      ans_two+=1
ans_inc = ans_two - 2*ans_unit
ans = (k*ans_unit)%1000000007
ans += int(k*(k-1)*ans_inc/2)%1000000007
ans = ans%1000000007
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]

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

Submission status: Wrong Answer

Solution code:
mod=1000000007

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
b=a*2
ans=chk=0
for i in range(n-1):
    for j in range(i+1,n):
        if a[i]>a[j]:
            chk+=1
            chk%=mod

for i in range(n):
    for j in range(n,n*2):
        if b[i]>b[j]:
            ans+=1
            ans%=mod
k-=1
k=k*(k+1)//2
print((chk*k%mod+ans*k%mod)%mod)

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a = list(map(int,input().split()))
n = len(a)
ans = 0
for i in reversed(range(n)):
    for j in range(i):
        if a[j] > a[j+1]:
            a[j],a[j+1] = a[j+1],a[j]
            ans += 1
tmp = 0
for i in range(n):
    for l in range(n):
        if  a[l] < a[i]:
            tmp+=1
            
ans = ans*k
k -=1
ans += tmp*k*(k+1)/2
print(int(ans%1000000007))

Submission status: Wrong Answer

Solution code:
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
num = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            num[i][1] += 1
        if (i < j) and (a[i] > a[j]):
            num[i][0] += 1
num_np = np.array(num)
ks = k * (k - 1) / 2
sum_left = sum(num_np[:,0])
sum_right = sum(num_np[:,1])
output = (sum_left * k) % 1000000007 + (sum_right * ks) % 1000000007
print(int(output % 1000000007))

Submission status: Wrong Answer

Solution code:
nk = input().split(" ");
n = int(nk[0]);
k = int(nk[1]);
a = input().split(" ");

waru = 10 ** 9 + 7;

for i in range(n) :
	a[i] = int(a[i]);

kaisu = [0] * n;
usiro = [0] * n;

for i in range(n) :
	for j in range(n) :
		if a[i] > a[j] :
			kaisu[i] += 1;
			if i < j :
				usiro[i] += 1;

ans = 0;
for i in range(n) :
	ans += ((k-1)*k * kaisu[i]/2 + usiro[i] *k)%waru
		
	
print(int(ans%waru));

Submission status: Wrong Answer

Solution code:
import numpy as np

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

Alist_sorted = sorted(Alist)
tmp = 0
tmp2 = 0
for i in range(1, len(Alist)):
    if Alist_sorted[i] == Alist_sorted[i-1]:
        tmp2 += 1
    else:
        tmp2 = 0
    tmp += i - (tmp2)
ans = (tmp * K * (K-1) / 2) % MOD

Alist = Alist[::-1]
for i in range(1, len(Alist)):
    ans += (np.sum(np.array(Alist[:i]) < Alist[i]) * K) % MOD
ans = ans % MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np

N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)

B = 0
C = 0

for i in range(N):
    D = A[i::]
    B += np.sum(D < A[i]) % (10**9 + 7)
    C += np.sum(A < A[i]) % (10**9 + 7)
    

E = B * K % (10**9 + 7)
F = C * ((int((K-1)*K/2)) % (10**9 + 7)) % (10**9 + 7)

print(int((E+F) % (10**9 + 7)))

Submission status: Wrong Answer

Solution code:
N_K = list(map(int,input().split()))

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

B = []
for i in A:
    B.append(i)
sequence=B*N_K[0]
#print(len(tentou))
#for j in range(len(tentou)):
#    num+=tentou[j]*(10**(len(tentou)-1-j))
count = 0
for i in range(1,len(sequence),1):
    for j in range(i,len(sequence),1):
        if sequence[i-1] > sequence[j]:
            count += 1


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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int
def mergeAndCountSplitInv(c, d):
    # c: left half, d: right half, both sorted
    nc = len(c)
    nd = len(d)
    b = [0] * (nc + nd)
    i, j = 0, 0
    splitInv = 0
    for k in range((nc + nd)):
        if i == nc: # c is used up
            b[k] = d[j]
            j += 1
            continue
        if j == nd: # d is used up
            b[k] = c[i]
            i += 1
            continue

        if c[i] <= d[j]: 
            b[k] = c[i]
            i += 1
        elif c[i] > d[j]:
            b[k] = d[j]
            splitInv += nc - i
            j += 1
    return b, splitInv

def sortCountInv(a):
    # a: list of int
    n = len(a)
    if n <= 1: # base case
        return a, 0
    c, leftInv = sortCountInv(a[ : n//2])
    d, rightInv = sortCountInv(a[n//2: ])
    b, splitInv = mergeAndCountSplitInv(c, d)
    # print(leftInv, rightInv, splitInv)
    return b, leftInv + rightInv + splitInv

def solve(N: int, K: int, A: "List[int]"):
    A_sort, inv = sortCountInv(A)
    t = [0] * N
    for i in range(1, N):
        if A_sort[i] > A_sort[i-1]:
            t[i] = t[i-1] + 1
        else:
            t[i] = t[i-1]
    count = inv * K + sum(t) * (K * (K-1))//2
    print(count % MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, A)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k=[int(i) for i in input().split()]
a_list=[int(s) for s in input().split()]

mod=10**9+7

# 単体の転倒数
first=0
for i in range(n-1):
    a=a_list[i]
    for j in range(i+1,n):
        if a>a_list[j]:
            first+=1

# 右に同じ列があったときの転倒数
a_num=len(set(a_list))
rightnum=a_num*(a_num-1)//2

ans=0
samecol=(k*(k-1)%mod//2)%mod
ans=(ans+samecol*rightnum%mod)%mod
ans=(ans+first*k)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
mod = 10**9+7
def main():
    n,k=map(int,input().split(' '))
    a = list(map(int,input().split(' ')))
    a_fall= 0
    a_rev = sorted(a,reverse=True)
    u_cnt = 0
    for i in range(n-1):
        a_sorted = sorted(a[i+1:])
        a_fall += bisect.bisect_left(a_sorted,a[i])
        a_fall %=mod
    for i in range(n-1):
        if a_rev[i] > a_rev[i+1]:
            u_cnt += n-i-1
    ans = a_fall+u_cnt*(k-1)//2
    ans %= mod
    ans *= k
    ans %= mod
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import bisect
input = sys.stdin.readline
 
def main():
    n,k = map(int,input().split())
    a=list(map(int,input().split()))
    b=a+a
    cnta=0
    cntb=0
    for i in range(n-1):
        for j in range(n-1-i):
            j+=i+1
            if(a[i]>a[j]):
                cnta+=1
                cnta=int(cnta%(1000000000+7))
    for i in range(2*n-1):
        for j in range(2*n-1-i):
            j+=i+1
            if(b[i]>b[j]):
                cntb+=1
                cntb=int(cntb%(1000000000+7))
    
    cntb-=2*cnta
    cntak=int((cnta*k)%(1000000000+7))
    cntbk=int((cntb* int(((k*(k-1)/2)%(1000000000+7))))%(1000000000+7))
    
    ans=(cntak+cntbk)%(1000000000+7)
    
    print(int(ans))
    
main()

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
if n == 1:
  print("0")
  exit()
ans_unit = 0
for i in range(n-1):
  for j in range(i+1, n):
    if a[i] > a[j]:
      ans_unit+=1
if k == 1:
  print(ans_unit)
  exit()
c = sum([a,a], [])
ans_two = 0
for i in range(2*n-1):
  for j in range(i+1, 2*n):
    if c[i] > c[j]:
      ans_two+=1
ans_inc = ans_two - 2*ans_unit
ans = k*ans_unit%1000000007
ans += int(k*(k-1)*ans_inc/2)%1000000007
ans = ans%1000000007
print(ans)

Submission status: Wrong Answer

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

const = pow(10, 9) + 7

c = 0

for i in range(n):
    for j in range(n - i - 1):
        # print(i, 10 - j - 1)
        if a[i] > a[n - j - 1]:
            c += 1

# print("c", c)

p = len(set(a))

q = p * (p - 1) / 2

# print("q", q)

ans = 0 + c * k + q * k * (k - 1) / 2

print(int(ans) % const)

Submission status: Wrong Answer

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

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

d={}
B=sorted(A)
for a in B:
	if a not in d:d[a]=1
	else:d[a]+=1

y=0
t=0
for a in d:
	t+=d[a]
	y+=t
y-=t

PP=10**9+7
print((((cnt*K)%PP+(y*(K*(K-1)//2))%PP))%PP)

Submission status: Wrong Answer

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


Aset = set(As)
As_tmp = [a for a in As]
from collections import defaultdict
d = defaultdict(int)

# 自分より小さい数は何個あるか
for a_set in sorted(Aset):
    cnt = 0
    for a in As_tmp:
        if a_set > a:
            cnt += 1
    d[a_set] = cnt
cnt = 0
# 1個目転倒数はいくつ？
for i,ai in enumerate(As):
    for aj in As[i:]:
        # print(bi,bj)
        if ai > aj:
            cnt += 1 
# 最大の点灯数は、最大値を引いたもの
sumA = 0
maxA = max(As)
for i,ai in enumerate(sorted(As,reverse=True)):
    for aj in As[i:]:
        if ai > aj:
            sumA += 1 
# print("sum",sumA,"cnt",cnt) 
mod = 10**9 + 7     
ans = sumA*(k-1)*k//2 + cnt*k
print(ans%mod)

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 = int(0)
        count_ = int(0)
        for j in range(N):
            if A[i] > A[j]:
                count_all += 1
                if i < j:
                    count_ += 1
        count += (count_ * K) % mod
        if K % 2 == 0:
            tmp1 = K / 2
            tmp2 = K - 1
        else:
            tmp1 = K
            tmp2 = (K - 1)/2
        count += (count_all * tmp1 % mod) * tmp2 % mod
        # import pdb; pdb.set_trace()
    print(int(count) % mod)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
a = N*[0]

for i in range(N):
  for j in range(N):
    if i<j and A[i]>A[j]:
      a[i]+=1

c = [i*K*(K+1)//2 for i in a]
print(sum(c)%(10**9+7))

Submission status: Wrong Answer

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

t=0
for i in range(n):
    for j in range(n):
        if i < j and a[i] > a[j]:
            t+=1
t*=k
for i in range(n):
    t+=int((k-1)*k/2)*len(list(filter(lambda m:m<a[i], a)))


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

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split(" ")))
B = []
count = 0
for i in range(K):
    for j in A:
        B.append(j)
for k in range(len(B)):
    for l in range(k+1, len(B)):
        if B[k] > B[l]:
            count += 1
print(count % (10^9+7))

Submission status: Wrong Answer

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

const = pow(10, 9) + 7

c = 0

for i in range(n):
    for j in range(n - i - 1):
        # print(i, 10 - j - 1)
        if a[i] > a[n - j - 1]:
            c += 1

print("c", c)

p = len(set(a))

q = p * (p - 1) / 2

print("q", q)

ans = 0 + c * k + q * k * (k - 1) / 2

print(int(ans) % const)

Submission status: Wrong Answer

Solution code:
import sys
import bisect
input = sys.stdin.readline
 
def main():
    n,k = map(int,input().split())
    a=list(map(int,input().split()))
    b=a+a
    cnta=0
    cntb=0
    for i in range(n-1):
        for j in range(n-1-i):
            j+=i+1
            if(a[i]>a[j]):
                cnta+=1
                cnta=cnta%(1000000000+7)
    for i in range(2*n-1):
        for j in range(2*n-1-i):
            j+=i+1
            if(b[i]>b[j]):
                cntb+=1
                cntb=cntb%(1000000000+7)
    
    cntb-=2*cnta
    cntak=int((cnta*k)%(1000000000+7))
    cntbk=int((cntb* int(((k*(k-1)/2)%(1000000000+7))))%(1000000000+7))
    
    ans=(cntak+cntbk)%(1000000000+7)
    
    print(int(ans))
    
main()