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 bisect
from collections import deque
import sys
MAX_INT = int(10e9)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
a = IL()

cnt = 0
for left in range(N):
  for right in range(left+1,N):
    if a[left] > a[right]:
      cnt += 1
cnt *= K

a.sort()
tmp = 0
for i in range(N-1):
  if a[i+1] > a[i]:
    tmp = i+1
  cnt += (((K-1)/2)*(2*tmp+(K-2)*tmp)) %mod

print(int(cnt) %mod)

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

Submission status: Wrong Answer

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
Alist = np.array(list(map(int,input().split())))
counter = 0
for i,A in enumerate(Alist,0):
    # print(A,"下")
    fir_tenti = np.count_nonzero(A>Alist[i:])
    # print(fir_tenti)
    counter += (K*fir_tenti*(K+1))/2
    second_tenti = np.count_nonzero(A>Alist[:i+1])
    # print(second_tenti)
    counter += (second_tenti*K**2-second_tenti*K)/2
print(int(counter%1000000007))

Submission status: Wrong Answer

Solution code:
n, k = map(int, input().strip().split())
list = list(map(int, input().strip().split()))
s = 0
t = 0
k = k%1000000007


for i in range(n):
    for j in range(i, n):
        if list[i] > list[j]:
            s += 1
            
list.reverse()           
for i in range(n):
    for j in range(i, n):
        if list[i] > list[j]:
            t += 1            
            
a = (k*(k+1)%1000000007)/2
b = (k*(k-1)%1000000007)/2

print(int(s*a+t*b)%1000000007)

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 += (lst2[i] * (k-1) * k) //2

ans += unit*k

print(ans%mod)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
c = 0
mod = (int)(1e9+7)
num = [0 for _ in range(2001)]
for v in a:
  num[v]+=1
for i in range(1,2001):
  num[i]+=num[i-1]
s = set(a)
for v in s:
  c += num[v - 1]
nn = k-1
if (nn%2==0):
  mul = int((nn//2 +  0.5 )*nn)
else:
  mul = (nn//2 +1)*nn
now = mul*c
now%=mod
total = 0
for i in range(n-1):
  for j in range(i+1,n):
    if a[i]>a[j]:
      total+=1
total*=k
total%mod
final = total+now
print(final%mod)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

a = bubble_sort(A.copy())
c = bubble_sort2(A.copy())

b = K * (K + 1) / 2 % mod
d = K * (K - 1) / 2 % mod
ans = (a * b) % mod + (c * d) % mod
print(int(ans % mod))

Submission status: Wrong Answer

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

for i in range(0,N):
    fr = len(list(filter(lambda x:x > A[i], A[:i+1])))
    ba = len(list(filter(lambda x:x > A[i], A[i+1:])))
    print(fr)
    print(ba)
    ans += ((0.5*(K**2 + K))*fr + (0.5*(K**2 - K) * ba)) % MOD
    print(ans)
print(int(ans % MOD))

Submission status: Wrong Answer

Solution code:
n,k = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
count = [0]*2000
A = (10**9)+7
c_in = 0
for i in range(n):
  for j, t in enumerate(a[:i]):
    c_in += int(t > a[i])
  count[a[i]-1] += 1
c_out = 0
for i in range(n):
  c_out += sum(count[:a[i]-1])
N = (c_in*k)%A + (c_out*k*(k-1)//2)%A
print(N)

Submission status: Wrong Answer

Solution code:
import numpy as np
N,K = map(int,input().split())
Alist = np.array(list(map(int,input().split())))
counter = 0
for i,A in enumerate(Alist,0):
    print(A,"下")
    fir_tenti = np.count_nonzero(A>Alist[i:])
    print(fir_tenti)
    counter += (K*fir_tenti*(K+1))/2
    second_tenti = np.count_nonzero(A>Alist[:i+1])
    print(second_tenti)
    counter += (second_tenti*K**2-second_tenti*K)/2
print(int(counter%1000000007))

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


cnt = 0

for i in range(N):
    for j in range(i+1, N):
        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

    cnt2 = (cnt2 * tmp) % MOD

cnt = (cnt + cnt2) % MOD

print(int(cnt))

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%MAX)*count_inversion(A))%MAX + (((K*(K-1)/2)%MAX)*count_bigger(A))%MAX
print(int(ans%MAX))

Submission status: Wrong Answer

Solution code:
import math

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

Submission status: Wrong Answer

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

# 転倒数
def mergecount(A,n):
    count=0
    for j in range(n):
        for i in range(j):
            if A[i]>A[j]:
                count+=1
    return count
B=A*2
a1=mergecount(A,N)
a2=mergecount(B,2*N)-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())
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)) % (10 ** 9 + 7)
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()))
a0_list = []
d_list = []
s_list = []

#a0_list
for k in range(N):
    c = 0
    for i in range(k+1,N):
        if A[k]>A[i]:
            c += 1
    a0_list.append(c)

#d_list
for l in range(N):
    c = 0
    for m in A:
        if A[l]>m:
            c += 1
    d_list.append(c)

for n in range(N):
    end = a0_list[n] + d_list[n]*(K-1)
    s = (a0_list[n] + end)*K/2
    s_list.append(s)

S = sum(s_list)
p = (10**9) + 7
ans = S%p
print(int(ans))

Submission status: Wrong Answer

Solution code:
INF = 1000000007

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

for i in range(len(a)):
    for j in range(len(a)):
        if i == j: continue
        #print(a[i], a[j])
        if a[i] > a[j]:
            if i < j:
                ans_i += 1
            else:
                ans_e += 1
x = ans_i * k
ans = ans_i + ans_e
y = int(ans * (k * (k-1) )/ 2)
print(int((x + y) % INF))

Submission status: Wrong Answer

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

A =[int(i) for i in input().split()]

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

firstcnt %= 1000000007

ans = firstcnt * K + seccnt * (K-1)*K/2
ans %= 1000000007

print(int(ans))

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

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((sum(s)*sum([k for k in range(K+1)]) - sum(p)))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

num = 0
num2 = 0
a_lst = []
for elem in input().split():
    if a_lst != [] and a_lst[-1] > int(elem):
        num += 1
    a_lst.append(int(elem))

if a_lst[-1] > a_lst[0]:
    num2 +=1
    
b_num = num
for i in range(2, k+1):
    b_num += (i - 1) * num2
    b_num += num + (i - 1) * (num + num2)

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

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 % (10 ** 9 + 7))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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


for sabun in range(2,K + 1):
    count = count*sabun + count
    
count = count%(10**9 + 7)
print(count)

Submission status: Wrong Answer

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

x = 0
for l in range(N - 1):
  for r in range(l + 1, N):
    if A[l] > A[r]:
      x += 1
# print(x)
      
AA = A + A
y = 0
for l in range(2 * N - 1):
  for r in range(l + 1, 2 * N):
    if AA[l] > AA[r]:
      y += 1
y -= 2 * x
# print(y)
  
# print(int((K * x + K * (K - 1) * y / 2) % (10 ** 9 + 7)))
# print(int((K * x  % (10 ** 9 + 7) + K * (K - 1) * y / 2  % (10 ** 9 + 7)) % (10 ** 9 + 7)))
kkmod = (K * (K - 1)) % (10 ** 9 + 7)
ans = (K * x + 1 / 2 * kkmod * y) % (10 ** 9 + 7)
print(int(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N, K = (int(x) for x in input().split())
A = list(map(int, input().split()))
B = []
ans = 0

for i in range(N * K):
    j = i
    if j > N - 1:
        j = 0
        B.append(A[j])
    else:
        B.append(A[j])

for i in range(len(B)):
    if i != len(B) - 1:
        for j in range(i + 1, len(B)):
            if B[i] > B[j]:
                ans += 1
                print(B[i], B[j])

print(ans % (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
B=int(s*K+(S*K*(K-1))/2)
print(B%1000000007)

Submission status: Wrong Answer

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

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

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 b[i] > b[j]:
      ans += 1

print(ans % (1000000000 + 7))

Submission status: Wrong Answer

Solution code:
from sys import stdin
import numpy as np
from operator import itemgetter

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

MOD = 10**9 + 7

array10=[0]*2001
is10=[0]*2001
AT=0
for i in range(N):
    a=int(A[i])
    is10[a]=1
    AT+=array10[a]
    for j in range(a):
        array10[j]+=1

AT=AT%MOD
sum10=[i*j for i, j in zip(array10,is10)]
sum10=sum(sum10)
ans=AT*K+sum10*K*(K-1)/2
print(int(ans)%MOD)

Submission status: Wrong Answer

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

listl = [0]*n
listr = [0]*n

tmpmax = 0
for i in range(1,n):
    tar = lista[i]
    for j in range(i,-1,-1):
        if lista[j]<tar:
            #listl[i] = listl[j]+1
            #break
            listl[i] +=1

for i in range(n-2,-1,-1):
    tar = lista[i]
    for j in range(i,n):
        if lista[j]<tar:
            #listr[i] = listr[j]+1
            #break
            listr[i] += 1

ans = 0
for i in range(n):
    f = listl[i]*(k-1)+listr[i]*k
    t = listr[i]
    ans += int(((f+t)*k)/2)
    ans = int(ans%((10**9)+7))
    
print(ans)

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 += int((0.5 * k * (k - 1) * sum(all_counts)) % (10 ** 9 + 7))
count += int((k * sum(single_counts)) % (10 ** 9 + 7))
print(int(count % (10 ** 9 + 7)))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    N,K = map(int, input().split())
    A = list(input().split())

    count = 0
    count_ = 0
    for i,a in enumerate(A):
        for j,target in enumerate(A):
            if j>i:
                if int(a) > int(target):
                    count += 1
            if int(a) > int(target):
                count_ += 1

    C = 0
    C = count * K + count_*(K*K-(1+K)*K/2)

    print(int(C%1000000007))

Submission status: Wrong Answer

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

mod=10**9+7

# 単体の転倒数
first=0
# 右に同じ列があったときの転倒数
rightnum=0
for i in range(n-1):
    a=a_list[i]
    for j in range(i+1,n):
        if a>a_list[j]:
            first+=1
    for a_all in a_list:
        if a>a_all:
            rightnum+=1

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
mod = 10**9 + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))
B1 = 0
B2 = 0
ll = [0] * N
ll2 = [0] * N
for i in range(0, N-1):
    for j in range(i+1, N):
        if A[i] > A[j]:
            ll[j] += 1
        else:
            for k in range(j+1, N-1):
                if A[i] < A[k]:
                    ll2[i] += 1
            # print(A[i], A[j], i, j)
        if A[j] > A[N-1]:
            B2 += 1
if A[N-1] > A[0]:
    ll[0] += 1
ans = 0
for i in range(N):
    if ll2[i] != 0:
        ans += (((ll[i] + ll2[i]) * K * (K+1))//2 - ll2[i] * K)
    else:
        ans += (ll[i] * K * (K+1))//2
print(ans % mod)

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%mod
print(int(ans%mod))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
mod = 10**9 + 7
N, K = map(int, input().split())
A = list(map(int, input().split()))
B1 = 0
B2 = 0
ll = [0] * N
ll2 = [0] * N
for i in range(0, N-1):
    for j in range(i+1, N):
        if A[i] > A[j]:
            ll[j] += 1
        else:
            for k in range(j, N-1):
                if A[i] < A[k]:
                    ll2[i] += 1
            # print(A[i], A[j], i, j)
        if A[j] > A[N-1]:
            B2 += 1
if A[N-1] > A[0]:
    ll[0] += 1
ans = 0
for i in range(N):
    if ll2[i] != 0:
        ans += (((ll[i] + ll2[i]) * K * (K+1))//2 - ll2[i] * K)
    else:
        ans += (ll[i] * 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()))

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

b = a * 2
ans = 0

for i in range(len(b)):
  for j in range(len(b[i:])):
    if b[i] > b[j]:
      ans += 1
  
ans /= 10^9+7
print(ans)

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
#print(t)
#exit()
#print(int((k*g%mod + t*(0.5*((k-1)*k))%mod)%mod))
print(int((k*g%mod + t*(0.5*((k-1)%mod*k%mod))%mod)%mod))
exit()

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 = np.zeros(N)
C = np.zeros(N)

for i in range(N):
    D = A[i:]
    B[i] = np.sum(D < A[i])
    C[i] = np.sum(A < A[i])
    

l = ((K-1) * K/2) % (10**9 + 7)
E = 0
F = 0
for i in range(N):
    E += B[i] * K % (10**9 + 7)
    F += C[i] * l % (10**9 + 7)

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

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) % MOD
ans += (tmp * ((K * (K - 1) % MOD) / 2)) % MOD
ans %= MOD

print(int(ans))

Submission status: Wrong Answer

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

for i in range(n):
	for j in range(n):
		if a[i] > a[j]:
			cnt2 += 1
print((int((k*(k-1)/2*cnt2)%(10**9+7))+(k*cnt1)%(10**9+7))%(10**9+7))

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)) % (10 ** 9 + 7)
count += (k * sum(single_counts)) % (10 ** 9 + 7)
print(int(count % (10 ** 9 + 7)))

Submission status: Wrong Answer

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

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)/2) - fflag)%mod
print(ans)

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
a2 = a + a
def tentou (l):
    count = [0]*len(l)
    for i in range(len(l)-1):
        for j in range(i+1,len(l)):
            if l[i] > l[j]:
                count[i] += 1
    return count
v = tentou(a)
vk = [0]*len(v)
for i in range(len(v)):
    vk[i] = v[i] * (k*(k+1))//2
S = sum(vk)
result = S % ((10**9) + 7)
print(result)

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))+jibun)%mod)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    
    A2 = A + A
    d2 = defaultdict(int)
    for i in range(2*N):
        for j in range(i,2*N):
            if A2[i] > A2[j]:
                d2[A2[i]] += 1

    d = defaultdict(int)
    for i in range(N):
        for j in range(i,N):
            if A[i] > A[j]:
                d2[A2[i]] -= 1
                d[A[i]] += 1
    ans = 0
    for key,value in d2.items():
        ans += (K / 2) * (2 * d[key] + (K - 1) * (value - d[key])) 
        
    print(int(ans) % (10 ** 9 + 7) )

main()

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)
print(count % (1000000000 + 7))

Submission status: Wrong Answer

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


a=list(map(int,input().split()))
ans=int(0)
ss=int(0)
tt=int(0)

for i in range(len(a)):
    p=int(sum([1 for j in a[i:] if a[i]>j]))
    q=int(sum([1 for j in a if a[i]>j]))
    ss+=p
    tt+=q


ss=ss%int((10**9+7))
tt=tt%int((10**9+7))
a1=ss*k%int((10**9+7))
a2=int((tt*k%int((10**9+7))))*(k-1)/2



print(int((a1+a2)%(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%mod)

Submission status: Wrong Answer

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