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: Runtime Error

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

N, K = map(int, input().split())
A = list(map(int, input().split()))
B = A * K
count = 0

for i in range(N):
    for j in range(N):
        if i < j:
            if B[i] > B[j]:
                count += (K**2 + K) // 2

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

Submission status: Runtime Error

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

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

print((cnt*k*(k+1)(/2%(10**9+7))

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

MOD = 10**9+7

class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    __radd__ = __add__

    def __rsub__(self, other):
        return (
            ModInt(other.x - self.x) if isinstance(other, ModInt) else
            ModInt(other - self.x)
        )

    __rmul__ = __mul__

    def __rtruediv__(self, other):
        return (
            ModInt(
                other.x * pow(self.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(other * pow(self.x, MOD - 2, MOD))
        )

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )

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

def main():
    N,K = map(int, input().split())
    aa = list(map(int, input().split()))
    aa = aa * 2
    bit = Bit(len(aa))
    ans = ModInt(0)
    for i in range(len(aa)):
        ans += i - bit.sum(aa[i])
        bit.add(aa[i], 1)
    ans *= (K-1)*K//2

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def resolve():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))

    A=[0]*2000
    B=[0]*2000
    mina=min(a)
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(i+1,N):
            if a[j]<a[i]:
                A[a[i]]+=1
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(N):
            if a[j]<a[i]:
                B[a[i]]+=1
    sumA=sum(A)
    sumB=sum(B)
    ans=int((0.5*(2*sumA+(K-1)*sumB)*K)%(10**9+7))
    print('{}'.format(ans))

resolve()

Submission status: Runtime Error

Solution code:
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=int(moz*(b[1]-1)/2)%(1000000000+7)
mozkk=int(mozk*b[1])%(1000000000+7)
print((mozkk+mo*b[1])%(1000000000+7))

Submission status: Runtime Error

Solution code:
mod=1e9+7
n,k=map(int,input().split())

l=list(map(int,input().split()))
ans=0
for i in range(len(l)):
    for j in range(i):
        if l[j]>l[i]:
            ans+=1
ans*=k

l.sort()

a=0
f=0
for i in range(n-1):
    if l[i]==l[i+1]:
        a+=f
    else:
        f+=1
a+=f
print(ans+a*k(k-1)//2)

Submission status: Runtime Error

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 + 1):]:
        if a1 > a2:
            inversion += 1

lower_count = [0] * (N + 1)
for a in a_list:
    lower_count[a] = len([x for x in a_list if x < a])
total_lower = sum(lower_count)


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

Submission status: Runtime Error

Solution code:
def resolve():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))

    A=[0]*2000
    B=[0]*2000
    mina=min(a)
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(i+1,N):
            if a[j]<a[i]:
                A[a[i]]+=1
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(N):
            if a[j]<a[i]:
                B[a[i]]+=1
    sumA=sum(A)
    sumB=sum(B)
    ans=(0.5*(2*sumA+(K-1)*sumB)*K)%(10**9+7)
    print('{}'.format(ans))

resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
N,k= map(int,input().split())
A= list(map(int,input().split()))
tree = [0] * (N+1)
M=10**9+7
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
c={}
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)
    if x not in c:
        c[x]=1
    else:
        c[x]+=1
c=sorted(c.items(),key=lambda x:x[0])
d,e=0,0
for j in c:
    d+=e
    e+=j[1]
print(((answer*k+(d%M)*(((((k-1)*k)//2))%M))%M))

Submission status: Runtime Error

Solution code:
from decimal import *
getcontext().prec = 20
n, k = map(int,input().split())
a = list(map(int,input().split()))
inner = Decimal(0)
outer = Decimal(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

print((Decimal(((inner) * (k)) + ((outer) * (Decimal(k) * (k-1)) / 2))%(1000000007)

Submission status: Runtime Error

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

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

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

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


#　そのブロック内での転倒数
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: Runtime Error

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 = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
bit = Bit(N*4)
ans = 0
hist = [0] * 3
for i in range(min(K, 3)):
    for j in range(N):
        ans = ans + i*N + j - bit.sum(A[j])
        bit.add(A[j], 1)
    hist[i] = ans
if K <= 3:
    print(ans)
else:
    ans = hist[0]
    a = (hist[1] - hist[0])
    d = (hist[2] - hist[1]) - (hist[1] - hist[0])
    ans = ans + (K-1) * (2*a + (K-2)*d) // 2
    print(int(ans % (10e+9 + 7)))

Submission status: Runtime Error

Solution code:
def resolve():
    N,K=map(int,input().split())
    a=list(map(int,input().split()))

    A=[0]*20
    B=[0]*20
    mina=min(a)
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(i+1,N):
            if a[j]<a[i]:
                A[a[i]]+=1
    for i in reversed(range(len(a))):
        if a[i]==mina:continue
        for j in range(N):
            if a[j]<a[i]:
                B[a[i]]+=1
    sumA=sum(A)
    sumB=sum(B)
    ans=(0.5*(2*sumA+(K-1)*sumB)*K)%(10**9+7)
    print(ans)

resolve()

Submission status: Runtime Error

Solution code:
a = list(map(int, "2 1".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)*(1+K)*K/2 - sum(p))%(1e9+7))

Submission status: Runtime Error

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
result = 0
while A != []:
    A_max_index = np.argmax(A)
    A_max = max(A)
    result = (result + sum([a<A_max for a in A[A_max_index+1:]]) * K + sum([a<A_max for a in A]) * int(((K-1) * K) / 2)) % (10**9 + 7)
    A.remove(A_max)
print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,k  = (int(i) for i in input().split())
a = [int(j) for j in input().split()]
b = a * k
print(b)
c = range(0,n)
resb = 0
ress = 0
for d in c:
 e = range(d,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 * k + ress * (k-1))

Submission status: Runtime Error

Solution code:
n ,k  = map(int,input().split())
a =input().split()
a1 = a * k
a_re = [int(s) for s in a1]


class Bit:
    def __init__(self, bb):
        self.size = bb
        self.tree = [0] * (bb + 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
            
bit = Bit(16)
ans = 0
aaa = 0
for i, p in enumerate(a_re):
  bit.add(p, 1)
  #aaa += p
  ans += i + 1 -bit.sum(p)
  
anss = ans % (10**9 + 7)

print(anss)

Submission status: Runtime Error

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
ans=0

print((jibun*k)%mod+int((1/2)*saki*k*(k-1))%mod)%mod)

Submission status: Runtime Error

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

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

def main():
    N,K = map(int, input().split())
    M = 10**9+7
    aa = list(map(int, input().split()))
    aa = aa * 2
    bit = Bit(len(aa))
    tmpans = 0
    for i in range(len(aa)):
        tmpans += i - bit.sum(aa[i])
        tmpans %= M
        bit.add(aa[i], 1)
    tmpans %= M
    ans = (K-1)*K//2
    ans %= M
    ans *= tmpans

    print(ans%M)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

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_tyouhuku * count_hairetu[i]

count_sum = (count_inv * K) + ((count_tyohuku + count_a) * (K-1))

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

Submission status: Runtime Error

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

    def sum(self, i):
        s = 0
        while i:
            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())
a = list(map(int, input().split()))

k = k % (10 ** 9 + 7)
bit = Bit(n * k)
cnt = 0
for i, t in enumerate(a * k):
    bit.add(t, 1)
    cnt += i+1-bit.sum(t)


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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**6)
N,k= map(int,input().split())
A= list(map(int,input().split()))
tree = [0] * (N+1)
M=10**9+7
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
c={}
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)
    if x not in c:
        c[x]=1
    else:
        c[x]+=1
c=sorted(c.items(),key=lambda x:x[0])
d,e=0,0
for j in c:
    d+=e
    e+=j[1]
print(((answer*k+d*(((((k-1)*k)//2))%M))%M))

Submission status: Runtime Error

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

right_counter = 0
all_counter = 0
multier = K * (K-1) / 2
if multier >= 10 ** 9 + 7:
    multier %= (10 ** 9 + 7)
threshold = -(-(10 ** 9 + 7) // multier)
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: Runtime Error

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

Submission status: Runtime Error

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

right_counter = 0
all_counter = 0
multier = K * (K-1) / 2
if multier >= 10 ** 9 + 7:
    multier %= (10 ** 9 + 7)
threshold = -(-(10 ** 9 + 7) // multier)
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(sum)

Submission status: Runtime Error

Solution code:
n ,k  = map(int,input().split())
a =input().split()
a1 = a * k
a_re = [int(s) for s in a1]


class Bit:
    def __init__(self, bb):
        self.size = bb
        self.tree = [0] * (bb + 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
 
bit = Bit(len(a_re))
ans = 0
aaa = 0
for i, p in enumerate(a_re):
  bit.add(p, 1)
  aaa += p
  ans += i + 1 - aaa
 
ans= ans % (10**9 + 7)

print(ans)

Submission status: Runtime Error

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

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

print(ans % (1000000000 + 7))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A=list(map(int,input().split()))
S=[0 for j in range(2000)]
S2=[0 for j in range(2000)]
count=0

for i in range(N):
  S2[A[i]]+=1
  for j in range(A[i]):
    count+=S2[j]*(K-1)*K//2


for i in reversed(range(N)):
  S[A[i]]+=1
  for j in range(A[i]):
    count+=S[j]*K*(K+1)/2
print(count%(1000000007))

Submission status: Runtime Error

Solution code:
import bisect
MOD = 10**9 + 7

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 = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
bit = Bit(pow(2,(n.bit_length()) + 1) * 2)
ans = 0
 
for i, p in enumerate(a):
    bit.add(p, 1)
    ans += i + 1 - bit.sum(p)
 
a.sort()
big = 0
for item in a:
    big += n - bisect.bisect_right(a, item)

times = (k * (k - 1) // 2) % MOD
ans2 = (ans * k) % MOD + (big * times) % MOD
ans2 %= MOD
print(ans2)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
A = input().split()
B = A*k
tentosu = 0

for i in range(len(B)):
    for j in range(len(B)):
        if j <i:
            continue
        if B[i] > B[j]:
            tentosu += 1
            
ans = tentosu % (10**9 + 7)
print(ans)

Submission status: Runtime Error

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

for i in range(1, len(A)):
    for h in range(i,len(A)):
        if A[i-1] > A[h]:
            num += 1
print(num%(10**9+7))

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
A = input().split()
B = A*k
tentosu = 0

for i in range(len(B)):
    for j in range(len(B)):
        if j <i:
            continue
        if B[i] > B[j]:
            print(i," ", j)
            tentosu += 1
print(tentosu)

Submission status: Runtime Error

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

b = a * k
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: Runtime Error

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
print(a, c)
ans = (a * b) % mod + (c * d) % mod
print(int(ans % mod))

Submission status: Runtime Error

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

for i in range(1, len(A)):
    for h in range(i,len(A)):
        if A[i-1] > A[h]:
            num += 1
print(num)

Submission status: Runtime Error

Solution code:
for i in range(1, len(A)):
    for h in range(i,len(A)):
        if A[i-1] > A[h]:
            num += 1
print(num)

Submission status: Runtime Error

Solution code:
import bisect
MOD = 10**9 + 7

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 = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
bit = Bit(n)
ans = 0
 
for i, p in enumerate(a):
    bit.add(p, 1)
    ans += i + 1 - bit.sum(p)
 
a.sort()
big = 0
for item in a:
    big += n - bisect.bisect_right(a, item)

times = (k * (k - 1) // 2) % MOD
ans2 = (ans * k) % MOD + (big * times) % MOD
ans2 %= MOD
print(ans2)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

n = []
n = input().split()

N = int(n[0])
K = int(n[1])

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

B = A * K

count = 0

for i in range(N * K) :
	for j in range(N * K - (i + 1)) :
		if B[i] > B[i + j + 1] :
			count = count + 1


#print('N = ', N, ' K = ', K)
#print('A = ', A)
#print('B = ', B)

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

Submission status: Runtime Error

Solution code:
import bisect
MOD = 10**9 + 7

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 = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]
bit = Bit(n)
ans = 0
 
for i, p in enumerate(a):
    bit.add(p, 1)
    ans += i + 1 - bit.sum(p)
 
a.sort()
big = 0
for item in a:
    big += n - bisect.bisect_right(a, item)

ans2 = (ans * k) + (big * k * (k - 1) // 2)
ans2 %= MOD
print(ans2)

Submission status: Runtime Error

Solution code:
import copy
import math
n, k = map(int, input().split())
a=[]
a=list(map(int, input().split()))
b=copy.copy(a)
ans=0
b.extend(a)
#print(b)
#print(b[n])

def fact(i):
    sum=1
    for j in range(1,k):
        sum*=j
    return j
        
    """
    if i==1:
        return 1
    else:
        return i*fact(i-1)
    """

for i in range(len(b)):
    tmp=0
    for j in range(i+1,len(b)):
        if j<n:
            if b[i]>b[j]:
                #print("B["+str(i)+"]:" + str(b[i])+" B["+str(j)+"]:"+str(b[j]))
                ans+=1
        else:
            if b[i]>b[j]:
                #print("B["+str(i)+"]:" + str(b[i])+" B["+str(j)+"]:"+str(b[j])+"#")
                tmp+=1
    tmp=int((tmp*sum(list(range(1,k))))%(1e+9+7))
    ans=int((ans+tmp)%(1e+9+7))
print(ans)

#ans=int((ans+1)%(1e+9+7))

Submission status: Runtime Error

Solution code:
N,k= map(int,input().split())
A= list(map(int,input().split()))
tree = [0] * (N+1)
M=10**9+7
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
c={}
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)
    if x not in c:
        c[x]=1
    else:
        c[x]+=1
c=sorted(c.items(),key=lambda x:x[0])
d,e=0,0
for j in c:
    d+=e
    e+=j[1]
print(((answer*k+d*(((((k-1)*k)//2))%M))%M))

Submission status: Runtime Error

Solution code:
def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k-1):
    a+=a

 
 
print(count_inversion(a)%100000007)

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = A*K
c = 0
for a1 in A:
  for a2 in A:
    if a1>a2: c+=1
c = c/2%(10**9+7)
print(int(c))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
DIV_NUM = 1000000007


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

if N==1:
    print(0)
    exit()

tree = [0] * (N+1)

# https://atcoder.jp/contests/chokudai_S001/submissions/6789704
def BIT_update(tree,x):
    while x <= N:
        tree[x] += 1
        x += x&(-x)
def BIT_sum(tree,x):
    s = 0
    while x:
        s += tree[x]
        x -= x&(-x)
    return s

answer = N*(N-1)//2
for x in A:
    answer -= BIT_sum(tree,x)
    BIT_update(tree,x)

B = sorted(A)

q=0
p=B[0]
r=0
for i in range(1,N):
    if B[i]>p:
        p=B[i]
        r=i
    q += r
# print(answer)
answer = answer % DIV_NUM
answer = (K * answer) % DIV_NUM
q = q % DIV_NUM
answer = answer + q * K * (K-1) // 2
answer = answer % DIV_NUM
print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
A = map(int, input().split())
A = A*K
c = 0
for a1 in A:
  for a2 in A:
    if a1>a2: c+=1
c = c/2%(10**9+7)
print(int(c))

Submission status: Runtime Error

Solution code:
def count_inversion(sequence):
    return sum(sum(m<n for m in sequence[i+1:]) for i,n in enumerate(sequence))
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(k-1):
    a+=a
print(a)
 
 
print(count_inversion(a)%100000007)