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())
As = [int(i) for i in input().split()]
mod = 10**9+7

As2 = As*2

# 個々の配列の転倒数
a = 0
for i in range(1, N):
    for j in range(i, N):
        if As[i-1] > As[j]:
            a += 1
# print(a)

# 2回目の配列が1回目の配列に対し何個転倒数を持つか
d = 0
for i in range(1, N * 2):
    for j in range(i, N * 2):
        if As2[i - 1] > As2[j]:
            d += 1
d -= a*2
# print(d)

K2 = K%mod
a2 = a%mod
d2 = d%mod
K_1 = (K-1)%mod

result = int( (K2*a2)%mod + ((K2*d2*K_1) * 0.5)%mod )

print(result%mod)

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

def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:n*k-1]) for i,n in enumerate(sequence))
  
ans = count_inversion(b)

print(ans % (1000000000 + 7))

Submission status: Wrong Answer

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

inv = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            inv += 1
total_inv = k * inv + k * (k - 1) / 2 * inv
dst = int(total_inv % (10e+9 + 7))
print(dst)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
kaisa = 0
ans_2 = 0
for i in range(1,len(A)):
    for j in range(0,i):
        if A[j]>A[i]:
            ans += 1
kaisa = ans
for i in range(K):
    ans_2 += kaisa
    kaisa += ans
print((ans_2)%10000000007)

Submission status: Wrong Answer

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

a=list(map(int,input().split()))
tentou1=0
for i in range(N):
  for j in range(i+1,N):
    if(a[i]>a[j]):
      tentou1+=1
a.sort()
a.reverse()
stentou=0
for i in range(N):
  for j in range(i+1,N):
    if(a[i]>a[j]):
      stentou+=1
answer=int(int(tentou1*K %1000000007 ) + int(stentou*K*(K-1)/int(2) %1000000007))
print(answer%1000000007)

Submission status: Wrong Answer

Solution code:
num, k = [int(s) for s in input().split()]
nums = [int(s) for s in input().split()]
behind = [0 for s in range(num)]
forward = [0 for s in range(num)]
for i in range(num):
  p = nums[i]
  for j in range(num - i - 1):
    if nums[i + j + 1] < p:
      behind[i] += 1
  for j in range(i):
    if nums[j] < p:
      forward[i] += 1

count = 0
count += int(sum(behind) * k * (k + 1) / 2)
count += int(sum(forward) * k * (k - 1) / 2)
count += sum(behind)
print(count % 1000000007)

Submission status: Wrong Answer

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

def cal(A, N):
    cnt1 = 0
    cnt2 = 0
    for i in range(N):
        for j in range(i+1,N):
            if A[N-1-j] > A[N-1-i]:
                cnt1 += 1
    for i in range(N):
        for j in range(N):
            if A[N-1-i] < A[j]:
                cnt2 += 1
    
    return cnt1, cnt2
    
    
x, y = cal(A,N)
R = int(1*10**9 +7)
tmp = int(y*K*(K-1)/2)
ans = tmp + x*K
print(ans%R)

Submission status: Wrong Answer

Solution code:
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(n):
    return n*(n+1)//2
n,k = map(int,input().split())
a = (list(map(int,input().split())))
sa = set(a)
if (len(sa) == 1):
    print(0)
else:
    t = sigma(len(sa)-1)*sigma(k-1)+bubble_sort(a)*k
    print(int(t%(10**9+7)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
A = list(map(int,input().split()))
a = len(A)
MOD = 10**9+7
mae_cnt = 0
ato_cnt = 0
ans = 0

def seki(num):
  return int(num*(num+1)/2)

for i in range(a):
  ans += (mae_cnt*seki(k)) % MOD
  ans += (ato_cnt*seki(k-1)) % MOD
  mae_cnt = 0
  ato_cnt = 0
  for j in range(i+1,a):
    if A[i] > A[j]:
      mae_cnt += 1

  for x in range(i):
    if A[i] > A[x]:
      ato_cnt += 1
      
ans += (mae_cnt*seki(k)) % MOD
ans += (ato_cnt*seki(k-1)) % MOD   

print(ans)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 24 21:32:07 2019

@author: kato yugo
"""

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

a = [0 for i in range(n+1)]

for i in range(n):
    a[i] = int(a_li[i])
a[n] = 10**10   
 
ans_memo = [0 for i in range(n)]   
for i in range(n):
    for j in range(i+1,n+1):
        if a[i]>a[j]:
            ans_memo[i] += 1

ans = 0

for i in range(n):
    q = ans_memo[i]
    ans += (q*k)
    
a2 = a
a3 = sorted(a2,reverse=True)

qqq = 0
memo2 = 1
for i in range(1,n):
    if a3[i] > a3[i+1]:
        qqq += memo2*(n-i)
        memo2 = 1
    elif a3[i] == a3[i+1]:
        memo2 += 1
    
total = int((k*(k-1))/2)
ans += qqq*total


print(ans%mod)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

list1 = input().split()
list2 = input().split()
N = int(list1[0])
K = int(list1[1])
a = [int(i) for i in list2]

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

res = ((cnt_l * K * (K+1) / 2) + (cnt_r * (K-1) * K /2)) % (10**9 + 7)

print(int(res))

Submission status: Wrong Answer

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

mod = 10**9+7


rightlist = [0 for i in A_list]
alllist = [0 for i in A_list]

for i in range(len(A_list)):
    ct1 = 0
    ct2 = 0
    a = A_list[i]
    right = A_list[i:]
    
    for j in right:
        #print(a,j)
        if a > j:
            ct1+=1
    
    for j in A_list:
        if a > j:
            ct2+=1
    rightlist[i] = ct1
    alllist[i] = ct2


R = int(sum(rightlist))
A  =int(sum(alllist))
K = int(K%mod)
R = int(R%mod)
A = int(A%mod)

ans = int(int(R*K)+A*int(K*(K-1)/2))
print(ans%mod)

Submission status: Wrong Answer

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

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

Blen = N * K

B = []

i = 0
while i < Blen:
    for j in range(0, N, 1):
        B.append(A[j])
        i += 1

ans = int(0)

for l in range(0, Blen - 1, 1):
    for m in range(0, Blen, 1):
        if l < m and B[l] > B[m]:
                ans += 1

print(ans)
ret = ans % 1000000007
print(ret)

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = [int(i) for i in 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

def count_inversion_B(sequence):
    count = 0
    for a in A:
        count = count + (A.count(a) - 1)
    return count

def count_inversion_C(sequence):
    count_hairetu = []
    for a in A:
        count_hairetu.append(A.count(a))
    return count_hairetu

count_inv = count_inversion(A)
count_tyouhuku = count_inversion_B(A)
count_hairetu = count_inversion_C(A)

count_a = 0
for i in range(len(count_hairetu)):
    count_a = count_a + (count_hairetu[i]-1) * count_hairetu[i]

count_sum = (count_inv * K) + ((N-1-count_tyouhuku+count_a) * (K-1))

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

Submission status: Wrong Answer

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

inv = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        if a[i] > a[j]:
            inv += 1
print(k * (k - 1) / 2)
total_inv = k * inv + k * (k - 1) / 2 * inv
dst = int(total_inv % (10e+9 + 7))
print(dst)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
def input(): return sys.stdin.readline().strip()
def gcd(x, y): return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y): return (x * y) // gcd(x, y)
MOD = 10 **9 + 7

# N = int(input())
# S = input()
N, K = map(int, input().split())
# 横
A = [int(x) for x in input().split()]
# 縦
# A = [int(input()) for _ in range(N)]
# 多次元
# L = [[int(x) for x in input().split()] for _ in range(N)]

ans = 0
tmp = 0

for i, a in enumerate(A) :
    for aa in range(i, N) :
        if a > A[aa] :
            ans += 1

for a in A :
    for aa in A :
        if a > aa :
            tmp += 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
n,k = map(int, input().split())
stra = list(map(int,input().split()))
strb = []
# for i in range(k):
# 	strb = strb + stra
ans = 0
sss = 0
# print(stra)
# print(strb)

for i in range(len(stra)-1):
	for j in range(i+1,len(stra)):
		if stra[i] > stra[j]:
			ans += 1
# for p in range(k):
# 	sss += p+1
sss = k * (k+1) /2
print((ans * sss) % (1000000000 + 7))

Submission status: Wrong Answer

Solution code:
mo=0
moz=0
mozk=0
mozkk=0
zemmo=0
intl=[]
tentl=[]
b=[]
for x in input().split(" "):
    b.append(int(x))
a=[]
for x in input().split(" "):
    a.append(int(x))
i=0
while i<len(a)-1:
    j=i+1
    while j<len(a):
        if a[i]>a[j]:
            mo+=1
        j+=1
    i+=1
i=0
intl=[0]*2001
for x in a:
    intl[x]+=1
i=b[0]
for x in intl:
    i-=x
    tentl.append(i)
for x in tentl:
    moz+=x
moz-=tentl[0]
mozk=moz%(1000000000+7)
mozkk=int(mozk*b[1]*(b[1]-1)/2)
print((mozkk+mo*b[1])%(1000000000+7))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))*2
count1=0
count2=0
for i in range(2*n):
  for j in range(i+1,2*n):
    if a[i]>a[j] and j<n:
      count1+=1
      count2+=1
    elif a[i]>a[j]:
      count2+=1

if k==1:
  print(count1%(10**9+7))
else:
  ans=((count2-2*count1)*(k%(10**9+7)*(k-1)%(10**9+7))/2+count1*k)%(10**9+7)
  print(int(ans))

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-1000000007
E=int((K-1)*D/2)%1000000007
print((C+S*E)%1000000007)

Submission status: Wrong Answer

Solution code:
from decimal import *
getcontext().prec = 50
N, K = map(int, input().split())
A = list(map(int, input().split()))

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

ans = Decimal(K * x % (10 ** 9 + 7)) + Decimal(K * (K - 1) * y / 2 % (10 ** 9 + 7))
ans = Decimal(ans % (10 ** 9 + 7))
print(int(ans))
# print(int((K * x  % (10 ** 9 + 7) + K * (K - 1) * y / 2  % (10 ** 9 + 7)) % (10 ** 9 + 7)))
#kkmod = (K * (K - 1)) % (10 ** 9 + 7)
#Kxmod = (K * x) % (10 ** 9 + 7)
#ans = (2 * Kxmod +  kkmod * y) % (10 ** 9 + 7)
#print(int(ans / 2 % (10 ** 9 + 7)))

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

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 = (sum_f + int(sum_ * (k - 1) / 2)) % MOD
    print(int(ans) % MOD * k % MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

right_counter = 0
all_counter = 0
threshold = 0
multier = K * (K-1) / 2
if multier >= 10 ** 9 + 7:
    multier %= (10 ** 9 + 7)
if multier > 0:
    threshold = -(-(10 ** 9 + 7) // multier)
else:
    threshold = 10 ** 9 + 7
threshold_right = -(-(10 ** 9 + 7) // K)
threshold = 10 ** 9 + 7
threshold_right = 10 ** 9 + 7
for i in range(N):
    a_i = a_array[i]
    left_over = 0
    right_over = 0
    for j in range(i):
        if a_array[j] < a_i:
            left_over += 1
    for j in range(i+1, N):
        if a_array[j] < a_i:
            right_over += 1
    right_counter += right_over
    all_counter += right_over + left_over
    if right_counter >= threshold_right:
        right_counter %= threshold_right
    if all_counter >= threshold:
        all_counter %= threshold
sum = all_counter * multier + right_counter * K
sum %= (10 ** 9 + 7)
print(int(sum))

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

Submission status: Wrong Answer

Solution code:
N,K = map(int, input().split())
A = [int(i) for i in 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

def count_inversion_B(sequence):
    count = 0
    for a in A:
        count = count + (A.count(a) - 1)
    return count

def count_inversion_C(sequence):
    count_hairetu = []
    for a in A:
        count_hairetu.append(A.count(a))
    return count_hairetu

count_inv = count_inversion(A)
count_tyouhuku = count_inversion_B(A)
count_hairetu = count_inversion_C(A)

count_a = 0
for i in range(len(count_hairetu)):
    count_a = count_a + (count_hairetu[i]-1) * count_hairetu[i]

count_sum = (count_inv * K) + ((N-1-count_tyouhuku) * (K-1))

print(count_sum%(10**9+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:
def parse_ans(answer):
    return answer % ((10 ** 9) + 7)


def get_sigma(a, d):
    n = K
    return int((1 / 2) * n * (2 * a + (n - 1) * d))


N, K = map(int, input().split())
As = [int(i) for i in input().split()]

# K=1で取られたマウントの数(初項) <- Bi>BjならBjはマウントを取られた index -> 場所
mounted = [0] * len(As)
# 自分より強い値　(公差)　index -> 場所
more_strong = [0] * len(As)

# 強いランキング
tuyosa_banduke = sorted(As, reverse=True)

for i in range(len(As)):
    tuyosa_rank = tuyosa_banduke.index(As[i])  # 0 -> 最強
    more_strong[i] = tuyosa_rank
    for j in range(i + 1, len(As)):
        if As[i] > As[j]:
            mounted[j] += 1

print(parse_ans(sum([get_sigma(mounted[i], more_strong[i]) for i in range(len(As))])))

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a0 = a[0]
an = a[n-1]
now = a0
c_self = 0
c_inter = 0
for i in range(n):
    for j in range(i,n):
        #print(i,j)
        #print("a",a[i],a[j])
        if a[i] > a[j]:
            c_self += 1
        if a[i] != a[j]:
            c_inter += 1

t =( (k-1) * k /2) % (10**9 + 7)
l = (k * c_self) % (10**9 + 7)
q = (t * c_inter) % (10**9 + 7)

ans = (l + q) % (10**9 + 7)
print(int(ans))

Submission status: Wrong Answer

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

mod = 10**9+7


rightlist = [0 for i in A_list]
alllist = [0 for i in A_list]

for i in range(len(A_list)):
    ct1 = 0
    ct2 = 0
    a = A_list[i]
    right = A_list[i:]
    
    for j in right:
        #print(a,j)
        if a > j:
            ct1+=1
    
    for j in A_list:
        if a > j:
            ct2+=1
    rightlist[i] = ct1
    alllist[i] = ct2


R = sum(rightlist)
A  =sum(alllist)
K = K%mod
R = R%mod
A = A%mod

ans = int(int(R*K)+A*int(K*(K-1)/2))
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

order = 0
inlist = 0

ans = 0
for i in range(N-1):
    for j in range(N):
        if(A[i] > A[j]):
            if(i >= j):
                inlist += 1
            else:
                order += 1

    ans += ((((K * (K+1)) // 2)%MOD) * (order%MOD)) %MOD
    order = 0
    ans += ((((K * (K-1)) // 2)%MOD) * (inlist%MOD)) %MOD
    inlist = 0

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split())
a = input().split()
cnt = 0
ans = 0
tmp = 0
clc = 1000000000 + 7

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

for j in range(k+1):
    ans += cnt*j

print(ans)

Submission status: Wrong Answer

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
kaisa = 0
ans_2 = 0
for i in range(1,len(A)):
    for j in range(0,i):
        if A[j]>A[i]:
            ans += 1
kaisa = ans
for i in range(K):
    ans_2 += kaisa
    kaisa += ans
print((ans_2)%10000000007)

Submission status: Wrong Answer

Solution code:
def main():
    _, K = map(int, input().split())
    A = [int(i)for i in input().split()]
    count = 0
    mod = (1000000000 + 7)
    for i, b1 in enumerate(A):
        for j, b2 in enumerate(A):
            if b1 > b2:
                if (i < j):
                    count += ((K * (1 + K) / 2))
                else:
                    count += ((K * (1 + K) / 2) - K)
    print(int(count % mod))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def parse_ans(answer):
    return answer % ((10 ** 9) + 7)


def get_sigma(a, d):
    n = K
    return int((1 / 2) * n * (2 * a + (n - 1) * d))


N, K = map(int, input().split())
As = [int(i) for i in input().split()]

# K=1で取られたマウントの数(初項) <- Bi>BjならBjはマウントを取られた index -> 場所
mounted = [0] * len(As)
# 自分より強い値　(公差)　index -> 場所
more_strong = [0] * len(As)

# 強いランキング
tuyosa_banduke = sorted(As, reverse=True)

for i in range(len(As)):
    tuyosa_rank = tuyosa_banduke.index(As[i])  # 0 -> 最強
    more_strong[i] = tuyosa_rank
    for j in range(i + 1, len(As)):
        if As[i] > As[j]:
            mounted[j] += 1
print(mounted)
print(more_strong)
print(parse_ans(sum([get_sigma(mounted[i], more_strong[i]) for i in range(len(As))])))

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
Num=0
for num in A:
  for i in range(N):
    if num>A[i]:
      Num+=1
ans=int(1/2*(val+val+Num*(K-1))*K)    
print(ans%(10**9+7))

Submission status: Wrong Answer

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

for i in range(n):
    cnt=0
    mi=0
    for j in range(n):
        if a[i]>a[j]:
            cnt=cnt+1
        if a[i]>a[j] and i>j:
            mi=mi+1
    if cnt==0:
        ans=ans+ cnt*(k-1) -mi*k
    else:
        ans=ans+ cnt*math.factorial(k-1) -mi*k

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

Submission status: Wrong Answer

Solution code:
_, K = map(int, input().split())
a = list(map(int, input().split()))
s = [sum([b > c for c in a]) for b in a]
p = [sum([l < a[i] for l in a[:i]]) for i in range(1, len(a))]
print(int((sum(s)*(1+K)*K/2 - sum(p))%(1e9+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

def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:n*k]) for i,n in enumerate(sequence))
  
ans = count_inversion(b)

print(ans % (1000000000 + 7))

Submission status: Wrong Answer

Solution code:
n,k=map(int,input().split())
a=list(map(int,input().split()))*2
count1=0
count2=0
for i in range(2*n):
  for j in range(i+1,2*n):
    if a[i]>a[j] and j<n:
      count1+=1
      count2+=1
    elif a[i]>a[j]:
      count2+=1

if k==1:
  print(count1%(10**9+7))
else:
  ans=((count2-2*count1)*(k*(k-1)%(10**9+7))/2+count1*k)%(10**9+7)
  print(int(ans))

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

if y != 0:
    ans = ( ((K*x)%M) + ( ((1/4)*N*(N-1) % M) * (K*(K-1)%M) ) % M ) % (M)
    print(int(ans))
else:
    print(0)

Submission status: Wrong Answer

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

right_counter = 0
all_counter = 0
threshold = 0
multier = K * (K-1) / 2
if multier >= 10 ** 9 + 7:
    multier %= (10 ** 9 + 7)
if multier > 0:
    threshold = -(-(10 ** 9 + 7) // multier)
else:
    threshold = 10 ** 9 + 7
threshold_right = -(-(10 ** 9 + 7) // K)
for i in range(N):
    a_i = a_array[i]
    left_over = 0
    right_over = 0
    for j in range(i):
        if a_array[j] < a_i:
            left_over += 1
    for j in range(i+1, N):
        if a_array[j] < a_i:
            right_over += 1
    right_counter += right_over
    all_counter += right_over + left_over
    if right_counter >= threshold_right:
        right_counter %= threshold_right
    if all_counter >= threshold:
        all_counter %= threshold
sum = all_counter * multier + right_counter * K
sum %= (10 ** 9 + 7)
print(int(sum))

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 = (sum_f + sum_ * (k - 1) / 2) % MOD
    print(int(ans) * k % MOD)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

if k == 1:
	ans = 0
	for i in range(n):
		for num in a[i:]:
			if a[i] > num:
				ans += 1
	print(ans)
	exit()

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 = sum(lis[n:])
d = sum(lis[:n]) - sum(lis[n:])

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

Submission status: Wrong Answer

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

a=list(map(int,input().split()))
tentou1=0
for i in range(N):
  for j in range(i+1,N):
    if(a[i]>a[j]):
      tentou1+=1
a.sort()
a.reverse()
stentou=0
for i in range(N):
  for j in range(i+1,N):
    if(a[i]>a[j]):
      stentou+=1
answer=int(int(tentou1*K) + int(stentou*K*(K-1)/int(2)))
print(answer%1000000007)

Submission status: Wrong Answer

Solution code:
n,k  = (int(i) for i in input().split())
a = [int(j) for j in input().split()]
b = a
#b = a * k
#print(b)
c = range(0,n)
resb = 0
ress = 0
for d in c:
 e = range(0,n)
 for f in e:
  #print(d,f)
  if b[d] > b[f]:
   print(b[d],">",b[f])
   print(d,f)
   resb = resb + 1
  if b[d] < b[f]:
    print(b[d],"<",b[f])
    ress = ress + 1
print(resb)
print(ress)
print(resb * k + ress * (k-1))

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

result =  (two_tento*k*(k-1))/2 + one_tento*k
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()))
memo = 0
for i in range(N):
  for j in range(i, N):
    if A[i] > A[j]:
      memo += 1 
memo *= K
kei = K * (K - 1) / 2
cnt = 0
for i in range(N):
  for j in range(N):
    if A[i] > A[j]:
      cnt += 1
memo = memo + cnt * int(kei)

ans = memo % (10**9 + 7) 
print(int(ans))

Submission status: Wrong Answer

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

mod = 10**9+7


rightlist = [0 for i in A_list]
alllist = [0 for i in A_list]

for i in range(len(A_list)):
    ct1 = 0
    ct2 = 0
    a = A_list[i]
    right = A_list[i:]
    
    for j in right:
        #print(a,j)
        if a > j:
            ct1+=1
    
    for j in A_list:
        if a > j:
            ct2+=1
    rightlist[i] = ct1
    alllist[i] = ct2


R = sum(rightlist)
A  =sum(alllist)
K = K%mod
R = R%mod
A = A%mod

ans = R*K+A*int(K*(K-1)/2)
print(ans%mod)

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
plus = 0
minus = 0
for i in range(n):
    for j in range(n):
        if a[i] > a[j]:
            if i < j:
                plus += 1
            elif j < i:
                minus += 1
plus_count = plus * k
plus_count %= (10**9 +7)
tiny = plus + minus
num = k*(k-1)
num %= (10**9 +7)
num = int(num/2)
count = plus_count + num * tiny
print(count % (10**9 +7))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n,k = map(int,input().split())
a = list(map(int,input().split()))
cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i] > a[j]:
      cnt += k*(k+1)/2

b = list(reversed(a))
for l in range(n-1):
  for m in range(l+1,n):
    if b[l] > b[m]:
      cnt += (k-1)*k/2
      
x = 10**9 + 7
print(int(cnt%x))

Submission status: Wrong Answer

Solution code:
import sys

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N, K = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
#B = A*K
#print("")
#print("A:", A)
#print("B:", B)


inner_list = [0]*N
for i in range(N):
    for j in range(i+1, N):
        if A[i] > A[j]:
            inner_list[i] += 1
        else:
            next
#print("inner_list:", inner_list)

inter_list = [0]*N
for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            inter_list[i] += 1
        else:
            next
#print("inter_list:", inter_list)

list_2 = [0]*N
for i in range(N):
    list_2[i] = inter_list[i] * int((K**2 - K)/2)
#print("list_2:",list_2)

B_inv_num = sum(inner_list)*K + int(sum(inter_list))
#print("B_inv_num:", B_inv_num)

if len(str(B_inv_num)) < 9:
    print(B_inv_num)
else:
    print(B_inv_num%(10**9+7))