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 = [int(i) for i in input().split()]

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = (f-g)#%mod

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
ans1 = (k*g%mod)
#ans2 = t*(0.5* (k-1)%mod * k%mod ) %mod
#ans2 = t*(0.5*((k-1)%mod*k%mod))%mod
ans2 = t*(0.5*((k-1)%mod*k%mod)%mod)%mod
print( int( (ans1%mod + ans2%mod)%mod ))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

AA = A + A

AA_re = list(reversed(AA))
A_re = list(reversed(A))

ans0 = 0
for i in range(N):
    a = A_re[i]
    for j in range(i + 1, N):
        b = A_re[j]
        if a < b:
            ans0 += 1


ans1 = 0
for i in range(N):
    a = AA_re[i]
    for j in range(i + 1, 2 * N):
        b = AA_re[j]
        if a < b:
            ans1 += 1


sa = ans1 - ans0
m = 10 ** 9 + 7


matu = ans0 + sa * (K - 1)
c = ans0 + matu

ans = c // 2 * K

if K == 0:
    print(ans0)
    exit()

ans = ans % m


print(ans)

Submission status: Wrong Answer

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

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

inv_sorted_A = 0
for i in range(0,N):
  for j in range(0,N):
    if i<j and sorted_A[i] < sorted_A[j]:
      inv_sorted_A += 1

count = (round(inv_sorted_A * (K * (K-1))/2)  + inv_A * K ) % 1000000007

print(count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
d=0
for i in range(n):
  for j in range(i+1,n):
    if a[i]>a[j]:
      d+=1
  for l in range(n):
    if a[i]>a[l]:
      c+=1
ans=int(k*d+c*k*(k-1)/2)
print(int(ans%(10**9+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):
            # print('--- ---', i,j)
            if i == j:
                continue
            if a[i] > a[j]:
                
                if i > j:
                    plus = int(k*(k-1)/2)
                    count += plus
                elif i < j:
                    plus = int(k*(k+1)/2)
                    count += plus


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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np

MOD = 1e+9 + 7
N, K = map(int, input().split())
Alist = list(map(int, input().split()))

Alist_sorted = sorted(Alist)
tmp = 0
tmp2 = 0
ans = 0
KK = (K * (K-1) / 2) % MOD
for i in range(1, len(Alist)):
    if Alist_sorted[i] == Alist_sorted[i-1]:
        tmp2 += 1
    else:
        tmp2 = 0
    tmp = (i - (tmp2))%MOD
    ans += (tmp * KK) % 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
ans = ans % MOD
print(int(ans))

Submission status: Wrong Answer

Solution code:
MOD = 1000000007
N,K = map(int,input().split())
A = list(map(int,input().split()))
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
def sigma(k):
    return int(k*(k+1)/2)
C = []
for k in range(2):
    C.extend(A)
cnt = bubble_sort(A)
diff = bubble_sort(C) - 2 * cnt
a = (K*cnt)
b = (diff*sigma(K-1))
print ((a+b)%MOD)

Submission status: Wrong Answer

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

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = (f-g)#%mod

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
ans1 = (k*g%mod)
#ans2 = t*(0.5* (k-1)%mod * k%mod ) %mod
ans2 = t*(0.5*((k-1)%mod*k%mod))%mod
print( int( (ans1%mod + ans2%mod)%mod ))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

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

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = (f-g)#%mod

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
ans1 = (k*g%mod)
ans2 = t*(0.5* (k-1)%mod * k%mod ) %mod
#t*(0.5*((k-1)%mod*k%mod))%mod
print( int( (ans1%mod + ans2%mod)%mod ))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

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(i+1,n):
    if a[i]>a[j]:
      d+=1
  for k in range(n):
    if a[i]>a[k]:
      c+=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())
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
ans = (k*(temp+temp*k)//2) % mod
    
print(ans)

Submission status: Wrong Answer

Solution code:
import math

def A():
    temp = input().split()
    M = int(temp[0])
    D = int(temp[1])

    if D<22:
        print(0)
        return
    
    ans = 0

    for i in range(1, M+1):
        for j in range(22, D+1):
            if (j%10) >= 2 and (j%10)*int(j/10) == i:
                ans += 1
    
    print(ans)

def B():
    temp = input().split()
    N = int(temp[0])
    K = int(temp[1])
    A = [int(i) for i in input().split()]

    basic_inv = 0
    for i in range(0, len(A)):
        for j in range(i+1, len(A)):
            if A[i] > A[j]:
                basic_inv += 1
    
    if K == 1:
        print(basic_inv)
        return

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

    
    s = int((K*(K-1))/2)
    num = s
    k_mod = K
    print((k_mod*basic_inv + num*inv)%(10**9+7))


B()

Submission status: Wrong Answer

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

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = (f-g)#%mod

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
ans1 = (k*g%mod)
ans2 = t*(0.5* (k-1)%mod * k%mod ) %mod
#t*(0.5*((k-1)%mod*k%mod))%mod
print( int( (ans1%mod + ans2%mod)%mod ))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

Submission status: Wrong Answer

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

AA = A + A

AA_re = list(reversed(AA))
A_re = list(reversed(A))

ans0 = 0
for i in range(N):
    a = A_re[i]
    for j in range(i + 1, N):
        b = A_re[j]
        if a < b:
            ans0 += 1


ans1 = 0
for i in range(N):
    a = AA_re[i]
    for j in range(i + 1, 2 * N):
        b = AA_re[j]
        if a < b:
            ans1 += 1


sa = ans1 - ans0
m = 10 ** 9 + 7


matu = ans0 + sa * (K - 1)
c = ans0 + matu

ans = c // 2 * K

if K == 0:
    print(int(ans0))
    exit()

ans = ans % m


print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a,b=list(map(int,input().split())),0
for i,j in enumerate(a):
    for h in a[i:]:
        if j<h:b+=k*(k-1)//2
        else:b+=k*(k+1)//2
print(b%(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
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(k*(k+1)/2)
sigmakn = int(k*(k-1)/2)
for i in range(n):
    ans = (ans + (sigmakp * b[i][1]) % mod) % mod
    ans = (ans + (sigmakn * b[i][0]) % mod) % mod
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

ansR = 0
ansL = 0

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


ansR %= MOD
ansL %= MOD
Rn = (k+1)*k%MOD/2
Ln = (k-1)*k%MOD/2

ans = ansR*Rn%MOD + ansL*Ln%MOD

print(int(ans%MOD))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math

def A():
    temp = input().split()
    M = int(temp[0])
    D = int(temp[1])

    if D<22:
        print(0)
        return
    
    ans = 0

    for i in range(1, M+1):
        for j in range(22, D+1):
            if (j%10) >= 2 and (j%10)*int(j/10) == i:
                ans += 1
    
    print(ans)

def B():
    temp = input().split()
    N = int(temp[0])
    K = int(temp[1])
    A = [int(i) for i in input().split()]

    basic_inv = 0
    for i in range(0, len(A)):
        for j in range(i+1, len(A)):
            if A[i] > A[j]:
                basic_inv += 1
    
    if K == 1:
        print(basic_inv)
        return

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

    
    s = int((K*(K-1))/2)
    num = s%(10**9+7)
    k_mod = K%(10**9+7)
    print((k_mod*basic_inv + num*inv)%(10**9+7))

B()

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%mod)*(s%mod))%mod)

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
    u = Counter(a)
    ul = list(u.keys())
    ul.sort(reverse = True)
    p = len(ul)   
    ans *= k
    temp = 0
    for i in range(p):
        temp += u[ul[i]]
        ans += (n-temp)*(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:
x = list(map(int, input().split()))
N, K = x[0], x[1]
A = list(map(int, input().split()))
count_up = 0
count_re = 0
waru = 10**9+7

num = K * (K - 1) / 2

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

result = (K * count_up + count_re * num) % waru

print(int(result))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

[N, K] = map(int, input().split())
As = list(map(int, input().split()))

g = [len(list(x[1])) for x in groupby(sorted(As))]

tmp = 0
count1 = 0
for x in g:
    count1 += x * tmp
    tmp += x
    
count1 *= int((K - 1) * K / 2)
count1 %= 1000000007

count2 = 0
for i in range(len(As) - 1):
    count2 += len(list(filter(lambda x: As[i] > x, As[i+1:])))

count2 *= K
count2 %= 1000000007

count = count1 + count2
count %= 1000000007
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
num = 10**9+7
for i in range(N):
  count = 0
  for j in range(N):
    if i < j and A[i] > A[j]:
      count += 1
  ans += count*K%num
for i in range(N):
  A.append(A[i])
for i in range(N):
  count = 0
  for j in range(N):
    if i != j and A[i] > A[j]:
      count += 1
  ans += (K*(K-1)/2*count)%num
print(int(ans%num))

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) %prime)
print(int(ret%prime))

Submission status: Wrong Answer

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

mod = 10**9+7

g = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a[i] > a[j]:
            #print(i,j)
            g += 1

if k == 1:
    print(g)
    exit()
    
a2 = []

for i in range(2*n):
    a2.append(a[i%n])
    
f = 0

for i in range(n):
    for j in range(2*n):
        if i == j:
            continue
        elif i >= j:
            continue
        if a2[i] > a2[j]:
            #print(i,j)
            f += 1

t = (f-g)#%mod

#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
#print(int(( (k%mod*g%mod)%mod + (t*(0.5*((k-1)%mod*k%mod)) ) %mod)%mod))
#print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
ans1 = (k*g%mod)
ans2 = t*(0.5* (k-1)%mod * k%mod ) %mod
print( int( (ans1 + ans2)%mod ))
#print(int(((k*g) + (t*(0.5*((k-1)*k))))%mod))
exit()

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

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

count2 = 0
laa = sorted(la)
for i in range(n):
    for j in range(n-i-1):
        jj = j+1+i
      
        if laa[i] < laa[jj]:
            count2 += 1

a = count * k
b = count2 * int((0.5)*(k-1)*k)
result = a+b

print(result%(pow(10,9)+7))

Submission status: Wrong Answer

Solution code:
n,K=map(int,input().split())
A=list(map(int,input().split()))
s=0
for i in range(1,n):
    k=i
    while A[k]<A[k-1]:
        A[k],A[k-1]=A[k-1],A[k]
        k-=1
        s+=1
        if k==0:
            break
j=0
l=1
S=0
while j<n-1:
    if A[j]==A[j+1]:
        l+=1
        j+=1
    else:
        S=S+l*(n-1-j)
        l=1
        j+=1
C=(s*K)%1000000007
D=(K-1)*K/2
D=int(D)%1000000007
S=S%1000000007
E=S*D%1000000007
print((C+E)%1000000007)

Submission status: Wrong Answer

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

rn_0 , rn_2 = 0, 0

for i in range(n-1):
  for j in range(i+1, n):
    if l[i] < l[j]:
      rn_0 += 1

m = l*2
for i in range(n*2):
  for j in range(0, i):
    if m[i] > m[j]:
      rn_2 += 1

rn = rn_0 * k*(k-1)/2 + rn_2 * k*(k+1)/2
print(int(rn%(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
b = [[0, 0] for _ in range(n)]
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i > j:
                b[i][0] += 1
            else:
                b[i][1] += 1
ans = 0
sigmakp = int(((k*(k+1))%mod)/2)
sigmakn = int(((k*(k-1))%mod)/2)
for i in range(n):
    ans += (sigmakp * b[i][1]) % mod
    ans += (sigmakn * b[i][0]) % 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 % (10**9+7)
sum_left = sum(num_np[:,0])  % (10**9+7)
sum_right = sum(num_np[:,1])  % (10**9+7)
output = (sum_left * k) % (10**9+7) + (sum_right * ks) % (10**9+7)
print(output % (10**9+7))

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
num = 10**9+7
for i in range(N):
  count = 0
  for j in range(N):
    if i != j and A[i] > A[j]:
      count += 1
  ans += count*K%num
for i in range(N):
  A.append(A[i])
for i in range(N):
  count = 0
  for j in range(N):
    if i != j and A[i] > A[j]:
      count += 1
  ans += (K*(K-1)/2*count)%num
print(int(ans%num))

Submission status: Wrong Answer

Solution code:
from numpy import array
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
div = 1000000007
na = array(A)
s = 0
s2 = 0
for i, n in enumerate(na[:-1]):
    tmp = na < n
    s += sum(tmp[i+1:])
    s2 += sum(tmp)
 
s = int(s)
s2 = int(s2)
print(int((s * K + s2 * (K-1) * K // 2 ) % div))

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
        dis %= (10**9+7)
a = dis * K % (10**9+7)
b = count*K% (10**9+7)
b = b *(K-1)% (10**9+7)
ans = (a+b//2)% (10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
x = list(map(int, input().split()))
N, K = x[0], x[1]
A = list(map(int, input().split()))
count_up = 0
count_re = 0
waru = 10**9+7

num = K * (K - 1) / 2

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

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

result = (K * count_up + count_re * num) % waru

print(int(result))

Submission status: Wrong Answer

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

inversion = 0
# for i, a1 in enumerate(a_list):
#     for a2 in a_list[i:]:
#         if a1 > a2:
#             inversion += 1
for i in range(len(a_list)):
    for j in range(len(a_list) - 1, i, -1):
        if a_list[j] < a_list[j - 1]:
            a_list[j], a_list[j - 1] = a_list[j - 1], a_list[j]
            inversion += 1

total_lower = 0
for a in a_list:
    total_lower += len([x for x in a_list if x < a])


total_k = (K * (K - 1)) // 2
total = (total_lower * total_k) % MOD + (inversion * K) % MOD
print(total)

Submission status: Wrong Answer

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

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

k = K %((10**9)+7)
temp = 0
for i in range(k, 1, -1):
  temp += k
c *= temp
#c %= (10*9+7)
print(c)

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):
  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%mod + 0.5*k%mod*(k-1)%mod*ans_2%mod
print(int(ans%mod))

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-1):
    for j in range(i+1,N):
        if A[i]>A[j]:
            c+=1
            c=c%d


cc=0

for i in range(N):
    for j in range(N):
        if A[i]>A[j]:
            cc+=1
            cc=cc%d



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

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

Submission status: Wrong Answer

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

rn_0 , rn_2 = 0, 0

for i in range(n-1):
  for j in range(i+1, n):
    if l[i] < l[j]:
      rn_0 += 1

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

rn = rn_0 * k*(k-1)/2 + rn_2 * k*(k+1)/2
print(int(rn%(10**9+7)))

Submission status: Wrong Answer

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

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

x = 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]
            x += 1
M = 10**9 + 7

AA = []
for i in range(N):
    AA.append(A[i])
for i in range(N):
    AA.append(A[i])

y = 0
NN = N*2
for i in range(NN):
    for j in range(NN-1, i, -1):
        if AA[j] < AA[j-1]:
            AA[j], AA[j-1] = AA[j-1], AA[j]
            y += 1

ans = ( ((K*x)%M) + ( ((1/2)*y % M) * (K*(K-1)%M) ) % M ) % (M)
print(int(ans))

Submission status: Wrong Answer

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

MOD = 1000000007
bigr = [0] * n  #右より大きい個数
bigl = [0] * n  #左より大きい個数

Sum = 0


#右・左より大きい個数を数え上げ
for i in range(n - 1):
  for j in range(i + 1, n):
    if a[i] > a[j]:
      bigr[i] += 1
    elif a[i] < a[j]:
      bigl[j] += 1
      

#足していく

for i in range(n):
  if bigr[i] != 0:
    for j in range(1, k + 1):
      Sum = (Sum + bigr[i] * j) % MOD
      
  if bigl[i] != 0:
    for j in range(1, k):
      Sum = (Sum + bigl[i] * j) % MOD
      
print(Sum)

Submission status: Wrong Answer

Solution code:

N,K=map(int,input().split(" "))
A=list(map(int,input().split(" ")))
#N=3
#K=3
#A=[1,3,2]
A1=[set() for _ in range(N)]
cnt=0
cnt1=0
for n1 in range(N):
    for n2 in range(N):
        if n1!=n2 and A[n1]>A[n2]:
            cnt+=1
        if n1<n2 and A[n1]>A[n2]:
            cnt1+=1

#ten=int(cnt1+cnt*(K**2-K)/2+cnt1*(K-1))
k2=(K**2)%(10**9+7)
ten1=int((k2*cnt)%(10**9+7))
ten2=int((K*cnt)%(10**9+7))
ten3=int((cnt1*K)%(10**9+7))
if ten1-ten2<0:
    ten=(((ten1-ten2)+10**9+7)/2)
else:
    ten=((ten1-ten2)/2)
ten=ten+ten3
print(int(ten%(10**9+7)))

Submission status: Wrong Answer

Solution code:
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum_(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

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


n, k = map(int, input().split())
ppp = list(map(int, input().split()))
bit = Bit(3000)
ans_ = 0

for i, p in enumerate(ppp):
    bit.add(p, 1)
    ans_ += i + 1 - bit.sum_(p)

mod = 10 ** 9 + 7
ans = (ans_ * k) % mod

ppp = [-i for i in ppp]
ppp_ = set(ppp)
dic1 = {}
dic2 = {}
for i in ppp_:
    dic1[i] = 0
    dic2[i] = 0

for i in ppp:
    dic1[i] += 1
    dic2[i] += 1
k_ = int(((k-1) * k / 2)) % mod
for i in ppp_:
    dic1[i] = 0
    ans += k_ * dic2[i] * sum(dic1.values())
    ans %= mod

print(ans%mod)

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
        dis %= (10**9+7)
a = dis * K % (10**9+7)
b = count*K% (10**9+7)
b = b *(K-1)% (10**9+7)//2
ans = (a+b)% (10**9+7)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

mod = 10 ** 9 + 7
n, k = list(map(int, input().split()))
nums = list(map(int, input().split()))

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
	return count

a = (count_inversion(nums) % mod) * k
if k == 1:
	print(a)
	sys.exit()

nums_s = sorted(nums)
b = count_inversion(nums_s + nums_s) % mod
c = ((k - 1) * k / 2) % mod

print(int((a + b * c) % mod))

Submission status: Wrong Answer

Solution code:
import numpy as np
N, K = map(int, input().split())
A_l = list(map(int, input().split()))
A = np.array(A_l)
count_ini = 0
for i in range(N-1):
    count_ini += np.count_nonzero(A[i::] < A[i])
        
count_r = 0
A_sorted = np.sort(A)
for i in range(N-1):
    count_r += np.count_nonzero(A_sorted < A[i])

count = (count_ini * K + K / 2 * (K - 1) * count_r) % (10 ** 9 + 7)

print(int(count))

Submission status: Wrong Answer

Solution code:
n,K=map(int,input().split())
A=list(map(int,input().split()))
s=0
for i in range(1,n):
    k=i
    while A[k]<A[k-1]:
        A[k],A[k-1]=A[k-1],A[k]
        k-=1
        s+=1
        if k==0:
            break
j=0
l=1
S=0
while j<n-1:
    if A[j]==A[j+1]:
        l+=1
        j+=1
    else:
        S=S+l*(n-1-j)
        l=1
        j+=1
C=(s*K)%1000000007
L=K-1000000007
D=(K-1)*L/2
D=int(D)%1000000007
S=S%1000000007
E=S*D%1000000007
print((C+E)%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) % (10*9 + 7)
sum_left = sum(num_np[:,0])
sum_right = sum(num_np[:,1])
output = (sum_left * k) % (10*9 + 7) + (sum_right * int(ks)) % (10*9 + 7)
print(output % (10*9 + 7))