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 numpy as np
N, K   = map(int, input().split())
A=np.array(list(map(int, input().split())))
right=[]
left=[]
for i in range(N):
    right.append(np.count_nonzero(A[i:] < A[i]))
    left.append(np.count_nonzero(A[:i] < A[i]))
ans=sum(right)*int(K/2*(1+K))+sum(left)*int((K-1)/2*K)+sum(right)
print(ans%(10**9+7))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
li = list(map(int,input().split()))
mod = 10**9 +7

ans_1 = 0
ans_2 = 0
for i in range(n-1):
  for j in range(i+1,n):
    if li[i] > li[j]:
      ans_1+= 1
for i in range(n):
  for j in range(n):
    if li[i] < li[j]:
      ans_2 += 1
ans = k*ans_1 + 0.5*k*(k-1)%mod*ans_2
print(ans_1)
print(ans_2)
print(ans%mod)

Submission status: Wrong Answer

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

single_counts = [0] * (n - 1)
all_counts = [0] * n
for i in range(n - 1):
  for j in range(i + 1, n):
    if As[i] > As[j]:
      single_counts[i] += 1
      all_counts[i] += 1
    elif As[i] < As[j]:
      all_counts[j] += 1
      
count = 0
count += 0.5 * k * (k - 1) * sum(all_counts)
count += k * sum(single_counts)
print(int(count % (10 ** 9 + 7)))

Submission status: Wrong Answer

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

sort_a = sorted(a, reverse=True)
num_a = 0
num_b = 0

for i in range(n-1):
    for j in range(i+1, n):
        if a[j] < a[i]:
            num_a += 1
        if sort_a[j] < sort_a[i]:
            num_b += 1
            
t = int(((k*(k-1))/2)*num_b) % 1000000007

total = (k * num_a + t) 

if k == 1:
    print(num_a)
else:
    print(total)

Submission status: Wrong Answer

Solution code:
n,k = list(map(int,input().split()))
A = list(map(int,input().split()))
mod = 10**9 + 7
c = 0
for i in range(n):
        a = 0
        p = 0
        b = 0
        d = 0
        for j in range(n):
                if i > j:
                        if  A[i] < A[j]:
                                a += 1
                        if A[i] > A[j]:
                                p += 1
                elif j > i:
                        if A[i] > A[j]:
                                b += 1
                        elif A[i] < A[j]:
                                d += 1
        c += (k*(k+1)*(a+d)//2 - k * d) #- (a * k)
        c %= mod
#c //= 2
c %= mod
if A[0] < A[-1]:
        c += k-1
        c %= mod
print(c)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
count = 0
com1 = 0
com2 = 0
for i in range(N):
	for j in range(N):
		if A[i]>A[j]:
			com1 +=1
	for l in range(i):
		if A[i] > A[i-l-1]:
			com2 +=1
	count += (K / 2) * (2 * (com1 - com2) + (K - 1) * com1)
	com1 = 0
	com2 = 0
print(int(count%1000000007))

Submission status: Wrong Answer

Solution code:
N,K=map(int,input().split())
A = list(map(int,input().split()))
MOD = 1000000007
cnt = 0
for i in range(N-1):
  for j in range(i+1,N):
    if ( A[i] > A[j] ):
      cnt += 1
aset = set(A)
ns = len(aset)

if ns%2==0:
  sumn = ns * ((ns-1)//2) + (ns//2)
else:
  sumn = ns * ((ns-1)//2)

if K%2==0:
  mulk = K * ((K-1)//2) + (K//2)
else:
  mulk = K * ((K-1)//2)
mulk %= MOD 
#print( cnt, sumn , mulk, (N-1)//2 );
print ( ((cnt * K)%MOD  + (sumn * mulk) % MOD) %MOD)

Submission status: Wrong Answer

Solution code:
import copy

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

# inversion number in A
 
def merge(A, left, mid, right):
    #generate L[0,...,n1] and R[0,...,n2]
    L = A[left:mid]
    R = A[mid:right]
    L += [10**10]
    R += [10**10]
    n_1 = mid - left
 
    #define the inversion number
    c = 0
    t = 0
 
    #merge L and R
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] > R[j]:
            A[k] = R[j]
            j += 1
            t += 1
        else:
            A[k] = L[i]
            c += (n_1 - i) * t
            i += 1
            t = 0
 
    return c
 
def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        c1 = mergeSort(A, left, mid)
        c2 = mergeSort(A, mid, right)
        c3 = merge(A, left, mid, right)
        return c1 + c2 + c3
    else:
        return 0

val = 0
for i in range(n):
    inv = 0
    sub = 0
    B = A[i + 1:] + A[:i]
    for j in range(n - 1):
        if A[i] > B[j] and j >= n - i:
            inv += 1
            sub += 1
        elif A[i] > B[j]:
            inv += 1

    val += inv * k * (k + 1) // 2 - sub * k
    val %= 10 ** 9 + 7

print(val)

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)-1):
    for j in range(len(lis_a)):
        if(lis_a[i] > lis_a[j]):
            temp += 1
#print(temp)
ans = (k*(temp+temp*k)/2) % mod
    
print(ans)

Submission status: Wrong Answer

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

b = []
for i in range(k):
  b = b + a

ans = 0
  
for i in range(len(b)):
  for j in range(k * n - 1):
    if i <= j and j <= k * n -1 and b[i] > b[j]:
      ans += 1

print(ans % (1000000000 + 7))

Submission status: Wrong Answer

Solution code:
N,K =map(int,input().split())
a = list(map(int,input().split()))
# print(a*K)
count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
    count %= (10 ** 9 + 7)
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
a = dis * K % (10**9+7)
b = round(count*K*(K-1)/2% (10**9+7))
ans = (a+b)% (10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
N,K=map(int,input().split())
l=list(map(int,input().split()))

cnt=0
cntt=0
p=10**9+7
for i in range(N):
	for j in range(N):
		if l[i]>l[j] and j>i:
			cnt+=1
for k in range(N):
	for m in range(N):
		if l[k]>l[m] and k>m:
			cntt+=1
Cn=cntt*int((K-1)*K/2)%p+int(K*(K+1)/2)*cnt%p
print(Cn%p)

Submission status: Wrong Answer

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

B = A * 2
base1 = 0
base2 = 0

for i in range(N):
    count1 = 0
    count2 = 0
    for j in range(i+1, i+N):
        if B[i] > B[j]:
            if j < N:
                count1 += 1
            else:
                count2 += 1
        
    base1 += count1
    base2 += count2

    count1 = 0
    count2 = 0
    
ans = int((1/2)*base1*K*(K+1)) + int((1/2)*base2*(K-1)*(K))
    
divisor = 1000000007

print(ans % divisor)

Submission status: Wrong Answer

Solution code:
def po(a,b):
    x=1
    for i in range(b):
        x=x*a
    return x

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(po(ans,k)-1)

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)+(sougou*K*(K-1)/2))%1000000007
print(round(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)-1):
    for j in range(len(lis_a)):
        if(lis_a[i] > lis_a[j]):
            temp += 1
print(temp)
ans = (k*(temp+temp*k)/2) % mod
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

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

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

cnt = cnt_1 * K + cnt_2 * int((K-1)*K/2)

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

Submission status: Wrong Answer

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

b = []
for i in range(k):
  b = b + a

ans = 0
  
for i in range(len(b)):
  for j in range(i, k * n - 1):
    if i <= j and j <= k * n -1 and b[i] > b[j]:
      ans += 1

print(ans % (1000000000+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
from functools import lru_cache

def main():
    count = 0

    n,k = map(int, input().split(' '))
    a = [i for i in map(int, input().split(' '))]

    for i in range(n):
        moto = a[i]
        for j in range(n):
            if i == j:
                continue
            if moto > a[j]:
                print(i,j)
                if i > j:
                    
                    plus = int(k*(k-1)/2)
                    count += plus
                elif i < j:
                    plus = int(k*(k+1)/2)
                    count += plus
                    

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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

saki=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            saki=saki+1
print(int(jibun*(k+1)+(1/2)*saki*k*(k-1)))

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
N,K=map(int,input().split())
l=list(map(int,input().split()))

cnt=0
cntt=0
p=10**9+7
for i in range(N):
	for j in range(N):
		if l[i]>l[j] and j>i:
			cnt+=1
for k in range(N):
	for m in range(N):
		if l[k]>l[m] and k>m:
			cntt+=1
Cn=cntt*int((K-1)*K/2)%p+int(K*(K+1)/2)*cnt%p
print(cnt,cntt)
print(Cn%p)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
time_ans = 0
A_sort = sorted(A)
before = -1
b = -1
for i in range(N):
        a_sorti = A_sort[i]
        if a_sorti == before:
                time_ans += b
                continue
        b = A_sort.index(a_sorti)
        time_ans += b
        before = a_sorti

for i in range(N):
        for j in range(i + 1,N):
                if A[i] > A[j]:
                        ans += 1
ans = int(time_ans * K * (K + 1) / 2) - K * (time_ans - ans)
print(ans)
print(ans % (10 ** 9 + 7))

Submission status: Wrong Answer

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

b = []
for i in range(k):
  b = b + a

ans = 0
  
for i in range(k * n -1):
  for j in range(i, k * n -1):
    if i <= j and j <= k * n -1 and b[i] > b[j]:
      ans += 1

print(ans % (1000000000+7))

Submission status: Wrong Answer

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

a = a * 2

lis = [0] * n * 2

for i in range(2*n):
	for num in a[i:]:
		if a[i] > num:
			lis[i] += 1

# 初項a, 公差d, 項数k

a = sum(lis[n:])
d = sum(lis[:n]) - sum(lis[n:])

ans = (0.5*k*(2*a+(k-1)*d)) % (10 ** 9 + 7)
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)

if K % 2 == 0:
    F = C * (((K-1) * (K/2)) % (10**9 + 7)) % (10**9 + 7)
else:
    F = C * ((((K-1)/2) * K) % (10**9 + 7)) % (10**9 + 7)

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

Submission status: Wrong Answer

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

a_sorted = sorted(a)

bit = [0] * 2001

inversion = 0
for i in range(n):
  bit[a[i]] += 1
  s = 0
  for j in range(a[i]+1):
    s += bit[j]
  inversion += i + 1 - s
  
inversion *= k
  
for i in range(n):
  inversion += (a_sorted.index(a[i]) * (k - 1) * k * (k - 1)) // 2
  
print(inversion % int(10**9 + 7))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np

n, k = map(int, stdin.readline().rstrip().split(' '))
arg = np.array(list(map(int, stdin.readline().rstrip().split(' '))))
small = []
for i, val in enumerate(arg):
    small.append([np.count_nonzero(arg[:i+1] < val), np.count_nonzero(arg[i+1:] < val)])
smallnd = np.array(small)
a, b = np.sum(smallnd, axis=0)
#k_d = k % (10**9+7)
res = k*(a*(k-1)+b*(k+1))//2
print(int(res % (10**9+7)))

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,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)%prime) *(k%prime) %prime) + ((sum(tento2)%prime) *(sowa(k-1) %prime)%prime)
print(ret%prime)

Submission status: Wrong Answer

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

print(jibun)
saki=0
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            saki=saki+1
print(saki)
print(int(jibun*(k+1)+(1/2)*saki*k*(k-1)))

Submission status: Wrong Answer

Solution code:
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
mod = 10**9+7
B = A*2
c = 0
for i in range(len(B)):
  t = B[i]
  for j in range(1,len(B[i:])):
    if t > B[i+j]:
      c += 1
      #print(t,B[i+j])
#print(c)
s = sum(range(K))
print((c*s)%mod)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 1000000007
ans = 0
fflag = 0
bflag = 0

for i in range(n):
    for j in range(n):
        if i > j:
            if a[i] > a[j]:
                fflag += 1
        if i < j:
            if a[i] > a[j]:
                bflag += 1

ans = int(((fflag+bflag)*(k*(k+1))%mod)/2) - fflag
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = map(int,input().split( ))
a = list(map(int, input().split( )))
lst=[0 for _ in range(2010)]
mod = 10**9+7
unit = 0
#print(n,k,*a)
for i in range(n):
    lst[a[i]] += 1
    for j in range(i):
        if a[i] < a[j]:
            #print(a[i],a[j])
            unit += 1
#print(unit)
lst2 = [0 for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i]>a[j]:
            lst2[i] += lst[a[j]]

#print(lst[:15])
#print(lst2[:15])
ans = 0
for i in range(n):
    ans += (lst[a[i]] * lst2[i] * (k-1) * k) //2

ans += unit*k

print(ans%mod)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9 + 7
length = len(A)
R_down = [0]*length
L_down = [0]*length

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

    R_down[i] = count

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

    L_down[i] = count

R = sum(R_down)*k*(k+1)/2 % mod
L = sum(L_down)*(k-1)*k/2 % mod
ans = (R + L) % mod
print(int(ans))

Submission status: Wrong Answer

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

array = list(map(int, input().split()))
one_tento = 0
for i in range(n-1):
    for j in range(i+1,n):
        if array[i] > array[j]:
            one_tento += 1

two_tento = 0
for ki in range(n):
    for l in range(n):
        if array[ki] < array[l]:
            two_tento += 1

shoko = one_tento
result =  k*(2*shoko+two_tento*(k-1))/2
waru = 7 + 10 ** 9
print(int(result % waru))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
h=0 #hidariyoridekai=0
m=0 #migiyoridekai=0
for i in range(n):
    for j in range(n):
        if (a[i]>a[j]) and (i>j):
            h += 1
        elif (a[i]>a[j]) and (i<j):
            m += 1
MOD = 10**9+7
ans = ( int(((k+1)%MOD)*(k%MOD)*m*0.5)%MOD + int(((k-1)%MOD)*(k%MOD)*h*0.5)%MOD)%MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
def count_inversion(sequence):
    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
    else:
        count = count%MAX
    return count%MAX

def count_bigger(sequence):
    count = 0
    for num1 in sequence:
        for num2 in sequence:
            if num1 < num2:
                count += 1
    else:
        count = count%MAX
    return count%MAX

MAX = 7 + 10**9
N, K = map(int,input().split())
A = list(map(int,input().split()))
ans = (K*count_inversion(A))%MAX + (K*(K-1)/2*count_bigger(A))%MAX
print(int(ans%MAX))

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])  % 1000000007
sum_right = sum(num_np[:,1])  % 1000000007
output = (sum_left * k) % 1000000007 + (sum_right * ks) % 1000000007
print(int(output % 1000000007))

Submission status: Wrong Answer

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


K_1 = Decimal(K)*Decimal(1+K)/Decimal(2) % Decimal(MOD)
K_2 = (K_1 - Decimal(K)) % Decimal(MOD)

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

res_prev = [0 for i in range(N)]

for i in range(N):
    a = As[i]
    for j in range(i):
        if a > As[j]:
            res_prev[i] += 1

ans = 0
for i in range(N):
    ans += (res_next[i] * K_1) % MOD
    ans += (res_prev[i] * K_2) % MOD
    ans %= MOD

print(int(ans))

Submission status: Wrong Answer

Solution code:

def main2():
    len_a, kurikaesi = map(int, input().split(" "))
    A = list(map(int, input().split(" ")))

    a_nomi_tenti = 0
    iko_tonari_tenti = 0
    for index, a_base in enumerate(A):
        for more_right in A[index+1:]:
            if a_base > more_right:
                a_nomi_tenti += 1
        for a_youso in A:
            if a_base > a_youso:
                iko_tonari_tenti += 1

    m = (kurikaesi-1)
    kosu = int((1+m) * m / 2)
    result = (a_nomi_tenti * kurikaesi) + (iko_tonari_tenti * kosu)
    print(result % (10**9+7))


main2()

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):
    tmp = 0
    tmp += (query[i]*(k*(k-1)%mod))
    tmp += (firstt[i]*(k*(k+1)%mod))
    tmp //= 2
    tmp %= mod
    ans += tmp
  print(int(ans%mod))
solve()

Submission status: Wrong Answer

Solution code:
N,K =map(int,input().split())
a = list(map(int,input().split()))
# print(a*K)
count = 0
dis = 0
for i in a:
    for k in a:
        if k < i:
            count +=1
    count %= (10 ** 9 + 7)
for i in range(N):
    for k in a[i:]:
        if k<a[i]:
            dis += 1
a = dis * K % (10**9+7)
b = round(count*K/2% (10**9+7)*(K-1))
ans = (a+b)% (10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
n, k = input().split()
N = int(n)
K = int(k)
A = [int(a) for a in input().split()]
countAList = []
countBList = []
for j in range(N):
    countA = 0
    countB = 0
    for i in range(N):
        if A[i] < A[j]:
            countB += 1
            if i > j:
                countA += 1
    countAList.append(countA)
    countBList.append(countB)
result = 0

for a, b in zip(countAList, countBList):
    result += K * a + int(b * K * (K - 1) / 2)
    result %= 10 ** 9 + 7
print(result % (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())
A = list(map(int,input().split()))
B = A*N
n = int(count_inversion(B))
ans = n % (10**9 + 7) 
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect
N,K = map(int,input().split())
A = list(map(int, input().split()))
B1=sorted(A)
LIM=10**9+7
Q1=[0]*N
Q2=[0]*N
for i in range(0,N):
  B2=sorted(A[i:])
  Q1[i] = bisect.bisect_left(B1,A[i])
  Q2[i] = bisect.bisect_left(B2,A[i])

#print(Q1)
#print(Q2)
S1=sum(Q1)
S2=sum(Q2)
#print(S1)
#print(S2)
ans=int(S1*K*(K-1)/2)+int(S2*(K))
print(ans % LIM)

Submission status: Wrong Answer

Solution code:

from bisect import bisect_right as br
from bisect import bisect_left as bl
mod = 10**9 + 7
def cal(num,freq):
    num = num%mod
    freq = freq%mod
    return (num*(1 + freq)*freq // 2)%mod

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

    tento = 0
    temp = []
    length = 0
    nottento = 0
    for a in A:
        point = br(temp,a)
        if length == point:
            if length> 0:
                if temp[-1] < a:
                    nottento += length
            temp.append(a)
        else:
            tento += length - point
            leftpoint = bl(temp,a)
            nottento += leftpoint
            temp.insert(point,a)
        length += 1
    print((cal(tento,K)%mod + cal(nottento,K-1)%mod)%mod)
    return
main()

Submission status: Wrong Answer

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

# 転倒数
def mergecount(A):
    count=0
    for j in range(N):
        for i in range(j-1):
            if A[i]>A[j]:
                count+=1
    return count
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()))
MOD = 10**9 + 7

def main():
    count1 = [0 for _ in range(N)]
    count2 = [0 for _ in range(N)]
    
    for i, a in enumerate(A[:-1]):
        c = 0
        for b in A[i+1:]:
            if a > b:
                c += 1
        count1[i] = c

    for i, a in enumerate(A):
        c = 0
        for b in A[:i]:
            if a > b:
                c += 1
        count2[i] = c + count1[i]

    s = (sum(count1) * K) % MOD
    s += (sum(count2) * (K-1) * K / 2) % MOD
    print(int(s%MOD))
                
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import collections
# from scipy.special import comb
from scipy.misc import comb


NUM_MOD = 10 ** 9 + 7


len_arr, num_repeat = map(int, input().split(' '))
arr = list(map(int, input().split(' ')))

differ = [len(list(filter(arr[i].__gt__, arr[i+1:]))) for i in range(0, len_arr)]
ans_internal = sum(differ)
num_kind = len(collections.Counter(arr))

if num_kind == 1:
    ans_external = 0
else:
    ans_external = (num_kind * (num_kind-1)) // 2

num_comb = comb(num_repeat, 2, exact=True)
ans = num_comb * ans_external + num_repeat * ans_internal
# print(f"inter: {ans_internal}, ext: {ans_external}, {num_comb} {num_repeat}")

print(ans % NUM_MOD)
exit(0)

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

if __name__ == '__main__':
    main()

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

a.sort()

q = 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]:
            q += 1

# print("c", c)

# print("q", q)

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

print(int(ans) % const)

Submission status: Wrong Answer

Solution code:
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
k_sum = (k+1)*k//2

ans = 0
minus = 0
for i in range(n):
    tentou = 0
    tentou2 = 0
    for j in range(n):
        if i<j and a[i]>a[j]:
            tentou += 1
        elif i >= j and a[i]>a[j]:
            tentou += 1
            minus +=1
    ans += tentou*k_sum

print(ans%1000000007)

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):
        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:

N, K = map(int, input().split())
A_lst = list(map(int, input().split()))
mod = 10**9 + 7

count1 = 0
count2 = 0
for i in range(N):
    for j in range(i+1, N):
        if j <= K * N - 1 and A_lst[i] > A_lst[j]:
            count1 += 1
    for j in range(N):
        if j <= K * N - 1 and A_lst[i] > A_lst[j]:
            count2 += 1

count2 %= mod

F = (K-1)*K // 2
F %= mod

ans = count1 * K + count2 * F
ans %= mod

if A_lst[N-1] > A_lst[0]:
    ans -= 1


print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

MOD = 10**9 + 7

N, K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

cnt = 0

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

cnt = cnt % MOD

if K >= 2:
    cnt = (cnt * K) % MOD

cnt2 = 0

if K >= 2:
    for i in range(N):
        for j in range(N):
            if A[i] < A[j]:
                cnt2 += 1
    cnt2 = cnt2 % MOD

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

    cnt2 = (cnt2 * tmp) % MOD

cnt = (cnt + cnt2) % MOD

print(int(cnt))

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()